Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Emit events in serial or parallel with support for synchronous and asynchronous listeners
CoffeeScript JavaScript

README.md

Event Emitter Grouped

Build Status NPM version NPM downloads Dependency Status Dev Dependency Status
Gratipay donate button Flattr donate button PayPayl donate button BitCoin donate button Wishlist browse button

Emit events in serial or parallel with support for synchronous and asynchronous listeners

Install

NPM

  • Use: require('event-emitter-grouped')
  • Install: npm install --save event-emitter-grouped

Browserify

  • Use: require('event-emitter-grouped')
  • Install: npm install --save event-emitter-grouped
  • CDN URL: //wzrd.in/bundle/event-emitter-grouped@2.4.3

Ender

  • Use: require('event-emitter-grouped')
  • Install: ender add event-emitter-grouped

Usage

// Importer
var EventEmitterGrouped = require('event-emitter-grouped').EventEmitterGrouped;

// Instantiate a new instance
var emitter = new EventEmitterGrouped();

// Bind an asynchronous event
emitter.on('hello', function(next){
    console.log('\tasync started');
    setTimeout(function(){
        console.log('\tasync finished');
        next();
    }, 1000);
});

// Bind a synchronous event
emitter.on('hello', function(){
    console.log('\tsync started and finished');
});

// Bind a prioritized event
vipListener = function(){
    console.log('\tvip started and finished');
};
vipListener.priority = 1;
emitter.on('hello', vipListener);

// Emit the events in serial (one after the other in a waiting fashion)
console.log('hello in serial started');
emitter.emitSerial('hello', function(err){
    console.log('hello in serial finished');

    // Emit the events in parallel (all at once)
    console.log('hello in parallel started');
    emitter.emitParallel('hello', function(err){
        console.log('hello in parallel finished');
    });
});

/* Outputs:
hello in serial started
    vip started and finished
    async started
    async finished
    sync started and finished
hello in serial finished
hello in parallel started
    vip started and finished
    async started
    sync started and finished
    async finished
hello in parallel finished
*/

EventEmitterGrouped, extends events.EventEmitter

  • 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 for
    • args... is an optional set of arguments that should be passed to the listeners when they are executed
    • next is an optional completion callback that will fire once all the tasks/listeners have compeleted
  • off - alias for events.EventEmitter.prototype.removeListener
  • emitSerial(eventName, args..., next?) - fetch the listener group and execute it in serial
  • emitParallel(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:

Sponsors

No sponsors yet! Will you be the first?

Gratipay donate button Flattr donate button PayPayl donate button BitCoin donate button Wishlist browse button

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)

Something went wrong with that request. Please try again.