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

> The implementation works, so you can test it yourself.

Sorry, didn't see the implementation, missed that.

----

So, now that I've looked at it and played with it, I think I would end up using it like this:

```js
var ac = new AbortController();
ac.signal.pr = abortableTask(ac.signal,() => new Promise(()=>{}));

// elsewhere
setTimeout(()=>ac.abort(),5000);
try {
   await Promise.race([
      someAsyncOp(),
      ac.signal.pr,
   ]);
}
catch (err) {
   // ..
}
```

So, IOW... a util like `abortableTask(..)` would save me doing the `addEventListener(..)` stuff, but it's a bit wonky that I essentially need to create a never-resolving promise to ensure that *only* the cancellation token ends up resolving (rejecting) the `pr` promise.

It's slightly beneficial for my purposes, but not as nice as if there was just a `pr` (of whatever name) as a lazy getter or method on the signal, or (as proposed earlier), a util that does *only* the `addEventListener(..)` part of the equation and not the task stuff.

On that last point, is there any chance that `abortableTask(..)` could have the second param as optional, so it skipped that part of the machinery if omitted (as would effectively be the case in my usage)?

-- 
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-774555123

Received on Saturday, 6 February 2021 22:49:54 UTC