Skip to content

Synchronous queue draining for WritableStream #465

@tyoshino

Description

@tyoshino

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 to push()) 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 has get chunk() and ack() method.
  • Calling ack() tells the WritableStream to fulfill the promise returned on write() 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions