Socket
Book a DemoInstallSign in
Socket

ewait

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ewait

WaitForAll and WaitForAny on EventEmitter.

0.2.1
latest
Source
npmnpm
Version published
Weekly downloads
1
-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

WaitForAll and WaitForAny for Node.js EventEmitter Build Status

WaitForAll and WaitForAny on EventEmitter instances.

Installation

npm install ewait

Unit tests

npm test

Usage

WaitForAny will wait until one of the specified EventEmitter is done. By contrast, WaitForAll will wait until all of the specified EventEmitter are done.

Upon successful completion, they will both emit a done event. On timeout, a timeout event will be emitted.

By default, WaitForAny and WaitForAll listen for the done event. This behavior can be altered by specifying a custom event type.

Example

Object-Oriented style

var all = new WaitForAll({
    timeout: 2000,      // Wait for 2000ms max.
    event: 'flushed'    // Wait for a custom event.
});

all.add([toilet1, toilet2, toilet3]);

all.once('done', function() {
    console.log('All done!');
});

all.once('timeout', function() {
    console.log('Timeout!');
});

all.wait();

Functional style

var toilets = [toilet1, toilet2, toilet3];

ewait.waitForAll(toilets, function(err) {
    console.log(err ? 'Timeout!' : 'Done!');
}, 2000, 'flushed');

API

Class WaitForAll

new WaitForAll([options])

Construct a new wait object with an 'AND' semantic.

options is an object with the following defaults:

options = {
    timeout: -1,  // No timeout.
    event: 'done' // Listen for 'done' events.
};

wait.add(emitters)

  • emitters: an array of EventEmitter

Add EventEmitter instances to wait on. Shouldn't be called after wait.

wait.wait()

Start waiting on EventEmitter instances.

Event: 'done'

  • results: the results returned by the EventEmitters

Emitted when the waiting criterion has been satisfied before timeout.

Event: 'timeout'

Emitted when timeout expires before waiting criterion is satisfied.

Class WaitForAny

new WaitForAny([options])

Construct a new wait object with an 'OR' semantic.

options is an object with the following defaults:

options = {
    timeout: -1,  // No timeout.
    event: 'done' // Listen for 'done' events.
};

wait.add(emitters)

  • emitters: an array of EventEmitter

Add EventEmitter instances to wait on. Shouldn't be called after wait.

wait.wait()

Start waiting on EventEmitter instances.

Event: 'done'

  • index: the index of the EventEmitter that has fired
  • args...: the parameters returned by the EventEmitter

Emitted when the waiting criterion has been satisfied before timeout.

Event: 'timeout'

Emitted when timeout expires before waiting criterion is satisfied.

ewait.waitForAll(emitters, callback, [event, timeout])

  • emitters: an array of EventEmitter
  • callback: continuation callback
  • event: the event name, defaults to 'done'
  • timeout: the timeout delay, defaults to -1

event defaults to done and timeout defaults to undefined.

The callback takes two arguments, err and results.

  • err: is null on successful wait and contains an error on timeout
  • results: the results returned by the EventEmitters

Behavior is the same as WaitForAll.

ewait.waitForAny(emitters, callback, [event, timeout])

See ewait.waitForAll for arguments.

Behavior is the same as WaitForAny.

License

This code is free to use under the terms of the MIT license.

Keywords

wait

FAQs

Package last updated on 22 Mar 2014

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.