-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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 return value on EventEmitter.once #25817
Labels
events
Issues and PRs related to the events subsystem / EventEmitter.
feature request
Issues that request new features to be added to Node.js.
Comments
Pull Request: #25818 |
bnoordhuis
added
events
Issues and PRs related to the events subsystem / EventEmitter.
feature request
Issues that request new features to be added to Node.js.
labels
Feb 2, 2019
@himself65 You closed the PR. Does that mean you're withdrawing this feature request? |
no just I forgot to open it, and I open it now |
Do you want to do something like this? const EventEmitter = require('events');
const ev = new EventEmitter();
EventEmitter.prototype.await = function(resolveEvent, rejectEvent) {
var _resolve,
_reject;
return new Promise( (resolve, reject)=>{
_resolve = resolve;
this.on(resolveEvent, resolve);
if (rejectEvent) {
_reject = reject;
this.on(rejectEvent, reject);
}
}).finally( () => {
this.off(resolveEvent, _resolve);
if (rejectEvent){
this.off(rejectEvent, _reject);
}
})
}
ev.await('ready')
.then((v) => {console.log(v); return v+2;})
.then((v) => {console.log(v); return v+3;})
.then((v) => {console.log(v); return v+4;})
.then((v) => {console.log(v); return v+5;})
.then((v) => {console.log(v)})
ev.emit('ready', 1);
/*
1
3
6
10
15
*/ |
yeah |
4 tasks
Add this support on #25818 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
events
Issues and PRs related to the events subsystem / EventEmitter.
feature request
Issues that request new features to be added to Node.js.
Is your feature request related to a problem? Please describe.
I'm trying to code a Promise method which will be called after
once
andon
have been called.and It will resolve the params that are returned from
once
andon
functions.I use it on server, the project code like this
but
once
just returns anull
because it only just be called and return nothing.node/lib/events.js
Lines 281 to 287 in 5e1d446
Describe the solution you'd like
All in all, I think it should do the same behavior whatever
on
oronce
The text was updated successfully, but these errors were encountered: