{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreia3p6ta2gyi2lmzgwiccfmbrtrprvpfbmokvnaythkg2uikeb6nqu",
    "uri": "at://did:plc:pi6woz4d47bkuws673w2il2r/app.bsky.feed.post/3mkutdaxfdua2"
  },
  "path": "/t/conduit-to-yield-first-lines-from-file-without-leaking-space-or-file-handles/14030#post_2",
  "publishedAt": "2026-05-02T12:33:07.000Z",
  "site": "https://discourse.haskell.org",
  "textContent": "This seems like a bug with `awaitForever` and `bracketP` and `take`:\n\n\n    {- cabal:\n    build-depends: base, text, directory, conduit\n    -}\n    import Conduit\n    import qualified Data.Conduit.Combinators as CC\n\n    main :: IO ()\n    main =\n      runConduitRes $\n           CC.enumFromTo (1 :: Int) 4\n        .| awaitForever (\\x ->\n           bracketP (pure ()) (\\_ -> putStrLn \"close\")\n             (\\_ -> CC.enumFromTo (1 :: Int) x)\n           .| CC.take 3)\n        .| CC.mapM_ (liftIO . print)\n        .| sinkNull\n\n\nThat outputs:\n\n\n    1\n    close\n    1\n    2\n    close\n    1\n    2\n    3\n    1\n    2\n    3\n    close\n    close\n",
  "title": "Conduit to yield first lines from file without leaking space or file handles?"
}