Skip to content

Make read requests abortable #1103

@domenic

Description

@domenic

Noted by @reillyeon in WICG/serial#112 (comment) .

For some cases it would be nice to dequeue (and possibly abort?) a given read request, without canceling the stream entirely. That is,

const controller = new AbortController();

// Assume "rs" contains chunks A and B.
const reader = rs.getReader();

const promise1 = reader.read();
const promise2 = reader.read({ signal: controller.signal });
const promise3 = reader.read();

controller.abort();

The intent here is that promise1 gets fulfilled with chunk A, and promise3 gets fulfilled with chunk B.

Some questions:

  • What does this do to promise2? Probably reject it with an "AbortError" DOMException (like in other AbortSignal scenarios).
  • What happens if abort is signaled after the read request is already fulfilled? Probably nothing (like in other AbortSignal scenarios).
  • Does this do more than just dequeue the read request? For example, could it be communicated all the way down to the underlying source, I guess via pull()? I don't think this helps much, but it's worth checking...

This is looking relatively straightforward to me to spec, and the use case @reillyeon presents is a good one. Should we just go for it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions