Re: [whatwg/streams] Reject pending reads when releasing reader (#1168)

> I slightly lean TypeError? We use it for a lot of similar situations in this spec, and now that abort reasons are a thing, we don't use AbortError DOMException directly at all.

Fair enough.

In #1103 we had an alternative API proposal: `readable.getReader({ signal })`. If we went that route, it *would* have made sense to reject with the signal's abort reason instead. But with the current API proposal, there's indeed no real interaction with an `AbortSignal`.

If desired, users could always propagate their abort reason manually:
```javascript
const abortController = new AbortController();
const { signal } = abortController;
const reader = readable.getReader();
signal.addEventListener("abort", () => {
  // Cannot propagate `signal.reason` to `releaseLock()`
  reader.releaseLock();
});
const read = reader.read().catch((e) => {
  // `e` will be a new `TypeError` instead of `signal.reason` here.
  // A user could propagate it manually though, if necessary:
  if (signal.aborted) {
    throw signal.reason;
  }
  throw e;
}).then(/* ... */);
abortController.abort(new Error("my custom abort reason"));
```



-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/pull/1168#issuecomment-1005807487
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/streams/pull/1168/c1005807487@github.com>

Received on Wednesday, 5 January 2022 15:28:57 UTC