Safe Haskell | None |
---|---|
Language | GHC2021 |
Polysemy.Http.Http
Description
Documentation
streamResponse :: forall c (r :: EffectRow) o h. Members '[Http c, Error HttpError :: (Type -> Type) -> Type -> Type, Resource] r => Request -> Maybe Int -> (forall x. StreamEvent o c h x -> Sem r x) -> Sem r o Source #
Initiate a request and stream the response, calling process
after connecting, for every chunk, after closing the
connection, and for the return value.
StreamEvent
is used to indicate the stage of the request cycle.
The optional Int
argument defines the minimal chunk size that is read for each callback. If it is Nothing
, the
stream reads what is available.
handle :: StreamEvent Double (IO ByteString) Int a -> Sem r a handle = \case StreamEvent.Acquire (Response status body headers) -> pure 1 StreamEvent.Chunk handle (StreamChunk c) -> pure () StreamEvent.Result (Response status body headers) handle -> pure 5.5 StreamEvent.Release handle -> pure ()
>>>
runInterpreters $ streamResponse (Http.get "host.com" "path/to/file") handle
5.5