Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

event-emitter-grouped

Package Overview
Dependencies
Maintainers
1
Versions
100
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

event-emitter-grouped

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

  • 2.3.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
394
decreased by-21.04%
Maintainers
1
Weekly downloads
 
Created
Source

Event Emitter Grouped

Build Status NPM version Gittip donate button Flattr donate button PayPayl donate button

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

Install

  1. Install Node.js
  2. npm install --save 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

You can discover the history inside the History.md file

License

Licensed under the incredibly permissive MIT License
Copyright © 2013+ Bevry Pty Ltd
Copyright © 2011-2012 Benjamin Arthur Lupton

Keywords

FAQs

Package last updated on 12 Jul 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc