I realise that nodejs has a powerful EventEmitter constructor which allows you to emit events. However, what EventEmitter is missing is a way for the event emitter to see what the listeners returned.
This is the functionality I am after:
e = new FantasticEventEmitter();
e.on( 'event1', function( param1, param2, cb ){
console.log("First listener called...")
cb( null, 10 );
});
e.on( 'event1', function( param2, param2, cb ){
console.log("Ah, another listener called!");
cb( null, 20 );
});
e.emit( 'event1', 'firstParameter', 'secondParameter', function( err, res ){
console.log("Event emitted, now res will be [ 10, 20]");
});
Basically, I want listeners to be able to register, getting called when an event is fired up, and:
- Listeners to be passed a callback parameter. the callback will "collect" the results
- Emitters to have a callback, which will get called with the result collections
Is there a library that does this already, before I reinvent the wheel?