Add a method like .addTeardown to AbortSignal #1289
Labels
addition/proposal
New features or enhancements
needs implementer interest
Moving the issue forward requires implementers to express interest
topic: aborting
AbortController and AbortSignal
What problem are you trying to solve?
(I did originally suggest this on the Observable proposal but it was suggested I propose this here instead.)
AbortSignal teardown is still fairly hazardous when relying on
.addEventListener
as the event may have already fired so it's very easy to have cleanup steps that don't occur when they should, the observable proposal adds a.addTeardown
method that calls the given teardown steps immediately if the associated signal is already aborted else adds a listener.Functionally there's not really any significant reason this method should be exclusive to Observables as the same patterns that have problems can occur when authoring code than involves Promises and/or callbacks.
What solutions exist today?
The alternative is writing a wrapper in userland, however in practice developers tend to forget the synchronously cancelled case which is why the Observable proposal even has the method.
How would you solve it?
I'd like to suggest that the method proposed as part of Observable is added to
AbortSignal
proper so that it can be used for all uses not just Observable.As an example of usage:
This basically mirrors the comparable usage in Observable:
Anything else?
No response
The text was updated successfully, but these errors were encountered: