1

I’m trying to consume an streamed http response. Problem is httpSource expects a MonadResource in the output conduit and I’m in IO so I figured I would get out a ResourceT IO :

main :: IO ()
main = do
  let c :: ConduitT () (Either String ServerEvent) (ResourceT IO) ()
      c = httpSource "http://localhost:3000/sse" $ toSrc . responseBody
  return ()
  where ...

Now I’m stuck with a c that is a conduit of ResourceT IO and about the only thing I can do is to runResourceT which I don't want. What I want is to get the same type but with IO :

ConduitT () (Either String ServerEvent) IO ()

I thought this must be easy but apparently not! best I could find was the https://hackage.haskell.org/package/conduit-1.3.4.3/docs/Data-Conduit-Lift.html which as far as I can see is not relevant to my case (I could be wrong though).

Ashkan Kh. Nazary
  • 21,844
  • 13
  • 44
  • 68
  • 1
    What you're asking for is probably impossible (or "possible but impractical/pointless"). The *function* you're probably looking for is `transPipe`, and `transPipe runResourceT $ httpSource ...` will type check. Unfortunately, it won't actually work as intended. Perhaps you could explain *why* you can't run your whole computation in `ResourceT IO` (i.e., why not `main = runResourceT $ do ...`), and I could try to provide a more helpful answer. – K. A. Buhr Feb 24 '23 at 19:08
  • @K.A.Buhr you are abs. right as I learned recently. How about you turn your comment into an answer, perhaps explaining why this is both impossible and not advisable. This way I can accept it as the answer and learn something as well :) – Ashkan Kh. Nazary Feb 25 '23 at 17:59

0 Answers0