-
Notifications
You must be signed in to change notification settings - Fork 10
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
Support for AbortController #20
Comments
I expect you can write a simple wrapper function for your use case that accepts the
If this sort of thing is useful feel free to open a PR to include it in the documentation, and if this is a frequently occurring pattern I guess it can make sense to include it as a separate utility function? |
Thank for you comments. It's very useful. I would like notice that NodeJS throw error on abort: const main = async () => {
const ee = new events.EventEmitter();
const ac = new AbortController();
setTimeout(() => ac.abort(), 1000);
for await (const message of events.on(ee, 'message', { signal: ac.signal })) {
console.log(message);
}
};
See also https://github.com/nodejs/node/blob/5ce015ec72be98f064041d1bf5c3527a89c276cc/lib/events.js#L982-L984 . I believe to mimic that behavior following changes is required:
The second difference I notice is that |
Hello,
I am porting code from NodeJS to browser. In NodeJS I use
require('events').on
(do not confuse withrequire('events').EventEmitter.on
).events.on
is available since NodeJS v13.6.0 and returns<AsyncIterator>
that iterateseventName
events emitted by the emitter. It support optionsignal
which can be used to cancel awaiting events. See details: https://nodejs.org/docs/latest-v16.x/api/events.html#events_events_on_emitter_eventname_optionsI would like replace
events.on
withEventIterator
, but it lack support signal aborting eg. viaAbortController
.AbortController
is standard interface in browser and have raising deployment in NodeJS too. In NodeJS classAbortController
is added in NodeJS v15.0.0 and since v15.4.0 is no longer experimental. See details: https://nodejs.org/api/globals.html#globals_class_abortcontrollerIs AbortController support in your area of interest?
The text was updated successfully, but these errors were encountered: