-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Best way to extend AbortController and AbortSignal? #13
Comments
Fascinating stuff. I'm having a hard time understanding some of what's being proposed here, as I'm not as deep into the problem and solution space as you all are. So please excuse any misunderstandings or dumb questions, and don't take my advice too seriously.
I don't think so, unless I'm misunderstanding. The point of AbortSignal/AbortController, at least, is allowing you to share the same AbortSignal among multiple fetches, or in general multiple abortable operations. It's a channel through which something is communicated, not a representation of any given event.
These examples are compelling, but I would solve them using "downcasting" or "separation" utility functions. E.g.: const newAbortSignal = AbortSignal.follow(taskSignal); // only follows the abort aspect
const newTaskSignal = TaskSignal.follow(taskSignal, { ignoreAbort: true }); // only follows the priority aspect
How deep or wide would we expect the hierarchy to get? I guess maybe fetch signals is our third example, hmm... but
Is this 2 or 3 in the linked doc? My gut reaction would be to prefer 3 to 2, FWIW. |
Thanks for taking the time to read and comment, much appreciated!
Ah, I guess I think of the signals conceptually as the messages/events that are being communicated, rather than the channel itself (although this is an important concept). Maybe that understanding is based on other systems? For example, POSIX signals are "delivered". There's also the Qt framework that uses signals and slots for object communication, "A signal is emitted when a particular event occurs." That pattern also shows up in boost. With POSIX signals, I think the "channel" is process-wide, and in signals-and-slots, the slots represent the channel(s). I wasn't sure how closely
Yeah I think doing something like this would be preferred, and thought of something similar as I was writing up the examples. I need to think about the shape a little bit; I think the tricky case is when combining priority and abort from different sources.
That's a good question; I don't know. The
It's (3) in the alternative approaches section, but confusingly |
Why would the IDL need to be updated? It already accepts all subclasses of |
@annevk you're right, the IDL wouldn't need to be updated; the spec would need to be updated to say what to do with each type of signal. At this point I'm happy with the inheritance approach. Being able to share |
See also https://github.com/whatwg/dom/labels/topic%3A%20aborting. If you want to help with those that'd be great. |
I'm going to close this for now as we're happy with the inheritance approach; I'll reopen if anything else comes up. |
For the
postTask
API, we need to build on top ofAbortSignal
andAbortController
to add reprioritizaton, and I'm wondering if folks have opinions on what they think the best (long-term) way to do that is.Our current implementation matches the FetchController proposal, including the comment about
FetchSignal
inheriting fromAbortSignal
. In IDL:But IMO the inheriting-from-
AbortSignal
approach comes with a few downsides:PrioritySignal
makes propagating individual signal components more difficult and less straightforward (see these examples)An alternative is to create separate signal components (in this case
PrioritySignal
, or maybeTaskPrioritySignal
) and optionally combine them in some way, for example a map of signals or a composite "meta-signal" using mixins.I think ideally we'd still have a composite
TaskSignal
for encapsulation, but make it extend all of the signals it supports. But since multiple inheritance isn't supported, the best we could probably do is use mixins. This has the downside, however, that sharing signals is more complicated — either APIs need to be adjusted to accept the new composite signal, or the individual signal needs to be "plucked out" (e.g.AbortSignal
) at callsites.I'm starting to lean towards the composite/mixin approach, but would like it better if there were an easier way to still share signals. One option might be to create a composite parent class which exposes a
.signals
property, which APIs could accept and pluck signals out of (e.g.composite.signals['abort']
).I wrote up a bunch more thoughts, along with what different API shapes look like and what I think the pros and cons are.
Thoughts? Strong opinions either way?
/cc @domenic and @jakearchibald who were at one time involved in
AbortSignal
andFetchSignal
and might have thoughts or know others that might./cc @jyasskin @natechapin @kjd564 who have been involved in conversations around this.
The text was updated successfully, but these errors were encountered: