Support for AsyncGenerator
event handlers, for streaming long running responses
#581
Closed
1 task done
Labels
Describe the feature
Provide a new utility that enables developers to write streamed, chunked or partial responses using an async generator:
When making this request you would immediately see the
<h1>Task results</h1>
appear in the response (also in the browser). Then every 5 seconds a new list item would appear as well. Finally, immediately after the 4th list item you also see "Job done".Added value
The main offering of this feature is a very intuitive way to let developers send results in pieces.
The code a developer writes using the proposed
sendYielding
is devoid of stream-API / readable-API logic and complications.Instead the focus lies on the business logic, with a single function body that you can easily await results in and easily send out status updates in between.
sendYielding provides a streaming response function where the developer gives up low-level control of the streaming, and in receives an ergonomic api in return.
What about
sendStream
?The
sendStream
function could already be used to build out the same example logic shown.But it would be in a very different form, because it would have to build a stream/readable.
For me, personally, trying to read the streaming apis of nodejs is like walking into a brick wall.
The details of stream modes and states are a high barrier to entry.
Not just in having to understand it, but to implement one as well. This mixes the business-logic with implementation details of streams.
It is good that
sendStream
exists, but it is too big a step when you just want to stream parts of a response without the need for low-level control.In all likelihood, the
sendYielding
would be built on top ofsendStream
.Use cases
Considerations / Open questions
sendYielding
wrapssendStream
, then expose the AsyncGenerator-to-Readable as a utility as well.Additional information
The text was updated successfully, but these errors were encountered: