3.0.1 • Published 9 years ago

asyncemit v3.0.1

Weekly downloads
10,295
License
MIT
Repository
github
Last release
9 years ago

asyncemit

Version npmBuild StatusDependenciesCoverage StatusIRC channel

The asyncemit allows you to emit an event to an EventEmitter3 asynchronously.

Installation

The module is released in the public npm registry and can be installed using:

npm install --save asyncemit

Usage

To make this pattern work there are a couple of preconditions that need to be satisfied:

  1. The method should be added on either a class that inherits from the EventEmitter or on a new EventEmitter instance.
  2. The number of arguments expected by a listener function should match the number of arguments passed to the asyncemit method excluding the event name.

See the following example:

var EventEmitter = require('eventemitter3')
  , asyncemit = require('asyncemit');

var ee = new EventEmitter();
ee.asyncemit = asyncemit;

//
// The next `foo` listeners will not be executed until `next` is called.
//
ee.on('foo', function (arg, next) {
  // Do things with arg?
  next();
});

//
// Still executed, but synchronously.
//
ee.on('foo', function (arg) {

});

ee.asyncemit('foo', 'bar', function (err) {
  //
  // The error argument will be set if one of the async listeners called the
  // `next` callback with an `error` argument.
  //
});

License

MIT

3.0.1

9 years ago

3.0.0

9 years ago

2.0.0

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago