-
-
Notifications
You must be signed in to change notification settings - Fork 33.5k
Closed
Labels
eventsIssues and PRs related to the events subsystem / EventEmitter.Issues and PRs related to the events subsystem / EventEmitter.feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.
Description
Is your feature request related to a problem? Please describe.
I'm trying to code a Promise method which will be called after once
and on
have been called.
and It will resolve the params that are returned from once
and on
functions.
I use it on server, the project code like this
module.exports.emitThen = async function emitThen (event, ...args) {
return Promise.all(
this.rawListeners(event).map(
listener => Promise.resolve()
.then(() => {
return listener.apply(this, args)
}
)
)
)
}
const res = await obj.emitThen(eventName, data).then(res=> {
// do something
})
but once
just returns a null
because it only just be called and return nothing.
Lines 281 to 287 in 5e1d446
function onceWrapper(...args) { | |
if (!this.fired) { | |
this.target.removeListener(this.type, this.wrapFn); | |
this.fired = true; | |
Reflect.apply(this.listener, this.target, args); | |
} | |
} |
Describe the solution you'd like
function onceWrapper(...args) {
if (!this.fired) {
this.target.removeListener(this.type, this.wrapFn);
this.fired = true;
return Reflect.apply(this.listener, this.target, args);
}
}
All in all, I think it should do the same behavior whatever on
or once
Metadata
Metadata
Assignees
Labels
eventsIssues and PRs related to the events subsystem / EventEmitter.Issues and PRs related to the events subsystem / EventEmitter.feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.