Re: [whatwg/dom] Expose an `aborted` promise on AbortSignal? (#946)

@benjamingr is there a real example you could point to that would benefit from this?

I find that I'm either using checkpoints, which is why I proposed https://github.com/whatwg/dom/issues/927, or I'm taking a thing that doesn't support signal and passing it to something like this:

```js
async function abortable(signal, promise) {
  if (signal.aborted) throw new DOMException('AbortError', 'AbortError');
  let listener;

  return Promise.race([
    new Promise((_, reject) => {
      listener = () => reject(new DOMException('AbortError', 'AbortError'));
      signal.addEventListener('abort', listener);
    }),
    promise,
  ]).finally(() => signal.removeEventListener('abort', listener));
}
```

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/946#issuecomment-773449680

Received on Thursday, 4 February 2021 16:48:17 UTC