[heycam/webidl] Proposal: DOMException.ignoreAborts(promise) (#933)

Ported from https://github.com/whatwg/dom/issues/881.

Consider the following code we're adding as an example to the Streams Standard in https://github.com/whatwg/streams/pull/1059:

```js
const controller = new AbortController();
const pipePromise = readable1.pipeTo(writable, { preventAbort: true, signal: controller.signal });

// ... some time later ...
controller.abort();

// Wait for the pipe to complete before starting a new one:
try {
 await pipePromise;
} catch (e) {
 // Swallow "AbortError" DOMExceptions as expected, but rethrow any unexpected failures.
 if (e.name !== "AbortError") {
  throw e;
 }
}

// Start the new pipe!
readable2.pipeTo(writable);
```

Wouldn't it be nice if we could do this instead?

```js
const controller = new AbortController();
const pipePromise = readable1.pipeTo(writable, { preventAbort: true, signal: controller.signal });

// ... some time later ...
controller.abort();
await DOMException.ignoreAborts(pipePromise);

// Start the new pipe!
readable2.pipeTo(writable);
```

The semantics here are roughly

```js
DOMException.ignoreAborts = function (promise) {
  if (!isPromise(promise)) {
    throw new TypeError();
  }

  return promise.catch(e => {
    if (isDOMException(e) && e.name === "AbortError") {
      // swallow exception
    } else {
      // rethrow
      throw e;
    }
  });
};
```

This is small enough that I'd be willing to implement it in Chromium, if given the binding team's blessing. (@yuki3, thoughts?)

Any thoughts from other implementers?

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/heycam/webidl/issues/933

Received on Thursday, 29 October 2020 15:51:42 UTC