npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

ewait

v0.2.1

Published

WaitForAll and WaitForAny on EventEmitter.

Readme

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.