-
Notifications
You must be signed in to change notification settings - Fork 168
Closed
Labels
Description
A WritableStream invokes its underlying sink's write()
method for each chunk in its queue. This completes only asynchronously on invocation of the fulfillment callback set to the promise returned by the write()
call. This means that one microtask is required to process each chunk.
We could change this to allow for synchronous draining by introducing an interface similar to the byobRequest
interface we've adopted for responding to BYOB reading in the underlying source of ReadableStream.
It'll be like:
- when a new chunk is enqueued,
write()
(or could be renamed topush()
) is invoked to notify the sink of that there're some chunks available for processing (redundant invocation is still prevented by the_writing
flag). - WritableStreamDefaultController has a getter named
writeRequest()
which hasget chunk()
andack()
method. - Calling
ack()
tells the WritableStream to fulfill the promise returned onwrite()
call on the WritableStream. - Once
ack()
is called,writeRequest()
is updated to represent the next chunk in the queue. If there's no chunk, it returns undefined.