[Haskell-cafe] Using Wai with Conduit and ResourceT (was Re: (New to Conduits) mixing lazy lists and Conduits?)

Jon Fairbairn jon.fairbairn at cl.cam.ac.uk
Thu Jun 28 21:05:21 UTC 2018


Michael Snoyman <michael at snoyman.com> writes:

> You can use Data.Conduit.Lazy for this.

Thanks. Not as straightforward as I had hoped, but I can see
why.

On a different note, still attempting to learn, I am trying to
use Network.Wai.Conduit with a conduit that has effects (ie
involves sourceFile), and so lives in (ResourceT IO). eg

example:: ConduitT i (Flush Builder) (ResourceT IO) ()

Now, responseSource expects IO, not ResourceT IO, so I don’t
think I can use that, so I wrote this:


> responseSourceRes status headers res_conduit
>   = responseStream status200 headers
>     (\send flush -> runConduitRes $ res_conduit
>                     .| mapM_ (\e->lift $ 
>                                   case e of 
>                                     Chunk c -> send c
>                                     Flush -> flush ))

which runs, but (rather to my surprise) doesn’t produce output
(not even headers) until all the effects have completed. That
gives rise to two questions:

Why does that not stream output?
What should I do instead?

-- 
Jón Fairbairn                                 Jon.Fairbairn at cl.cam.ac.uk



More information about the Haskell-Cafe mailing list