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

@jakearchibald 

It's the same reason you see the "deferred" pattern still used in promises, like by extracting the resolve/reject methods from inside a promise constructor and then using them elsewhere externally to what was inside the promise constructor: sometimes it's really inconvenient (or impractical) to stuff all the logic that determines resolution of the promise inside that single constructor.

In my case, I actually have many different places that need to observe the promise attached to the signal, some inside the internals of my library, and some in the userland functions that people write and pass into my library.

So, I need to be able to pass around both a `signal` and a `pr` promise that's attached to that signal, because in different places you need access to one or the other. For convenience, I store that `pr` as a property on the signal, so that I'm only passing around the single entity that has both forms of "observation" (signal or promise) available.

At any given moment, there might be quite a few places in the program that are observing the single `pr` (like via `Promise.race(..)`) and several others that are directly observing the `signal` (like `fetch(..)` calls). All those different places in the code cannot pragmatically be nested (or even invoked) from inside a single "asyncTask" callback, the way your util assumes.

So, similar to resolve/reject extraction, I am essentially needing to "extract" a promise for the signal aborting, and store that and use it around.

Right now I do this by making my own calls to `addEventListener(..)` and `removeEventListener(..)`. It's fine but it has some ugliness and potential for leakage.

I was asked if this utility being contemplated (for Node and for the web) could be useful for my purposes. Hopefully this helps explain the ways it does and doesn't fit with what you're advocating for here.

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

Received on Sunday, 7 February 2021 14:12:22 UTC