You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
events: removeListener event should be passed the user's listener function when using once() #5551
When using ee.once(), the user's listener function is wrapped. This is correctly accounted for during addListener when emitting the 'newListener' event, but not during removeListener and the 'removeListener' event.
I can PR later this evening - just opening the issue for the moment.
Test case:
'use strict';constassert=require('assert');constEventEmitter=require('events');constee=newEventEmitter();functionmyListener(){};letaddedType=null;letaddedListener=null;letremovedType=null;letremovedListener=null;ee.on('removeListener',(type,listener)=>{removedType=type;removedListener=listener;});ee.on('newListener',(type,listener)=>{addedType=type;addedListener=listener;});ee.once('foo',myListener);ee.emit('foo');process.on('exit',()=>{assert.equal('foo',addedType);assert.equal(addedListener,myListener);assert.equal('foo',removedType);process._rawDebug('next assertion will fail');assert.equal(removedListener,myListener);});
next assertion will fail
assert.js:89
throw new assert.AssertionError({
^
AssertionError: { [Function: g] listener: [Function: myListener] } == [Function: myListener]
at process.<anonymous> (/home/omsmith/ee-remove-listener-test/index.js:33:9)
at emitOne (events.js:77:13)
at process.emit (events.js:169:7)
1st PR is OK. 2nd PR has problem.
Removing the wrapper should be specified, otherwise it will remove the first listener which may not be added by "once".
Activity
simonkcleung commentedon Mar 5, 2016
1st PR is OK. 2nd PR has problem.
Removing the wrapper should be specified, otherwise it will remove the first listener which may not be added by "once".
events: fix 'removeListener' event after #once
events: fix 'removeListener' event after #once
jasnell commentedon Apr 29, 2016
Fix landed in #6394