Event Emitter Grouped
Emit events in serial or parallel with support for synchronous and asynchronous listeners
Install
- Use:
require('event-emitter-grouped')
- Install:
npm install --save event-emitter-grouped
Usage
var EventEmitterGrouped = require('event-emitter-grouped').EventEmitterGrouped;
var emitter = new EventEmitterGrouped();
emitter.on('hello', function(next){
console.log('\tasync started');
setTimeout(function(){
console.log('\tasync finished');
next();
}, 1000);
});
emitter.on('hello', function(){
console.log('\tsync started and finished');
});
vipListener = function(){
console.log('\tvip started and finished');
};
vipListener.priority = 1;
emitter.on('hello', vipListener);
console.log('hello in serial started');
emitter.emitSerial('hello', function(err){
console.log('hello in serial finished');
console.log('hello in parallel started');
emitter.emitParallel('hello', function(err){
console.log('hello in parallel finished');
});
});
getListenerGroup(eventName, args..., next?)
- returns a TaskGroup where each listener is a task, ordered by the highest priority listeners first
eventName
is the event that we should get the listeners forargs...
is an optional set of arguments that should be passed to the listeners when they are executednext
is an optional completion callback that will fire once all the tasks/listeners have compeleted
off
- alias for events.EventEmitter.prototype.removeListeneremitSerial(eventName, args..., next?)
- fetch the listener group and execute it in serialemitParallel(eventName, args..., next?)
- fetch the listener group and execute it in parallel
History
Discover the change history by heading on over to the HISTORY.md
file.
Contribute
Discover how you can contribute by heading on over to the CONTRIBUTING.md
file.
Backers
Maintainers
These amazing people are maintaining this project:
No sponsors yet! Will you be the first?
Contributors
These amazing people have contributed code to this project:
Become a contributor!
License
Licensed under the incredibly permissive MIT license
Copyright © 2013+ Bevry Pty Ltd us@bevry.me (http://bevry.me)
Copyright © 2011-2012 Benjamin Lupton b@lupton.cc (http://balupton.com)