-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is needed
Description
Describe the solution
To create better hooks for common web APIs, it would be good to allow for an AbortSignal to be passed as an option to a subscriber:
const handler = () => {}
const controller = new AbortController();
const sub = obs.subscribe(handler, { signal: controller.signal });(see #16, WICG/observable#12)
Basic framework for how this implementation should look like:
- An optional options argument can be passed into
.subscribethat has a field for anAbortSignal - An event listener gets added to the abort signal that kicks off the cleanup work for a subscriber when the signal gets aborted (effectively the same as calling sub.cancel
Where we'd add the options argument:
eventkit/packages/async-observable/lib/observable.ts
Lines 129 to 133 in 926196b
| subscribe(callback?: SubscriberCallback<T>): Subscriber<T> { | |
| if (!callback) callback = () => {}; | |
| const subscriber = new CallbackSubscriber(this, callback); | |
| return subscriber; | |
| } |
Some Q's to answer with this implementation --
- Say an AbortSignal gets emitted which kicks off the cleanup action. Now there isn't an entry point for us to await for the cleanup work to be finished! This is because the only place that we wait for cleanup work is in
.dispose(which is called by.cancel, see ref)- A potential solution is to have all the cleanup work be added to the promise set for the subscriber instead
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is needed