Skip to content

implement streaming response body#21

Open
CrowdHailer wants to merge 1 commit intogleam-lang:mainfrom
CrowdHailer:stream-response
Open

implement streaming response body#21
CrowdHailer wants to merge 1 commit intogleam-lang:mainfrom
CrowdHailer:stream-response

Conversation

@CrowdHailer
Copy link
Contributor

I use this in a lustre application.
The relevant code looks like

effect.from(fn(dispatch) {
  promise.await(fetch.send_bits(request), fn(response) {
    dispatch(StartStreaming)
    let assert Ok(response) = response
    use result <- promise.await(fetch.stream_bytes_body(response.body, fn(bytes) {
      dispatch(StreamedBody(bytes))
      promise.resolve(Nil)
    }))
    dispatch(StreamResult(result))
    promise.resolve(Nil)
  })
  Nil
})

It seems to be working ok for me.

await callback(bytes);
}
} catch (error) {
return new Error(new UnableToReadBody());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because there's only one error kind maybe this should just be an Error(Nil) that is returned?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant