Reputation: 36520
I have a shared event emitter say myEmitter.
myEmitter.on('fire', callback1);
myEmitter.on('fire', callback2);
...
myEmitter.on('fire', callbackN);
Now the problem is: I want myEmitter.on('fire', myTopCallBack);
and I want myTopCallBack to be the first callback function to be called when 'fire' event happens.
Is it possible to subscribe a callback as the first callback?
Upvotes: 0
Views: 178
Reputation: 203329
You can use emitter.prependListener()
:
myEmitter.on('fire', callback1);
myEmitter.on('fire', callback2);
...
myEmitter.on('fire', callbackN);
myEmitter.prependListener('fire', myTopCallBack);
Upvotes: 1