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.
|
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
Is your feature request related to a problem? Please describe.
I'm trying to code a Promise method which will be called after
onceandonhave been called.and It will resolve the params that are returned from
onceandonfunctions.I use it on server, the project code like this
but
oncejust returns anullbecause 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
onoronce