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 🙏

© 2024 – Pkg Stats / Ryan Hefner

waitron

v2.0.1

Published

Monster child of callback and semaphore without any promises

Downloads

8

Readme

waitron

Waitron provides a kind of asynchronous-semaphore-like like functionality (Asynchronous_semaphore): it creates an object through which asynchronous operations can let others know that they need to "hold on" for them, until they can "go" on.

With each call to hold method, caller marks object as "delayed" and gets a function that, when called, will finish that "delay". Calling go will remove the initial "delay" and wait for any other "delays" before calling back. Once all "delays" are finished, no more can be created (well... they can, they just won't delay anything).

It allows to start multiple asynchronous and synchronous functions and wait for all of them to finish before continuing. It is similar to async.parallel, but also differs quite a bit:

  • it does not call/execute those functions, it merely provides simple way for them to mark when they're done;
  • it waits for all of them to call back and gathers all errors before calling back (async.parallel calls back after first error);
  • it does not gather and pass any results from those functions when calling back;

Unless you need these, async.parallel might be a better choice for you. Or maybe even neo-async.parallel, which seems to be even faster.

Installation

npm install waitron

or:

npm install https://github.com/ahwayakchih/waitron

Usage

Example use:

const waitron = require('waitron');

// Somewhere inside rocket-manned module...
process.on('prepare-for-launch', hold => {
  // Fastening seatbelts is asynchronous, we have to wait
  // until everyone is done.
  pilots.fastenSeatbelts(hold());
  passengers.fastenSeatbelts(hold());
});

// Somewhere else inside rocket-log module...
process.on('prepare-for-launch', hold => {
  // We do not need to delay anything.
  console.log('Preparing for launch');
});

// Somewhere in command center...
var launcher = waitron();
process.emit('prepare-for-launch', launcher.hold);
var selfTest = launcher.hold();
selfTest() && launcher.go(null, errors => {
  // If everything is OK, launch!
  if (!errors) {
    start();
  }
});

Benchmarks

These benchmarks are just to make sure that working with Waitron is not much slower than working with async.parallel. Both modules provide different functionality, so they shouldn't be evaluated solely by results of these benchmarks. You can re-run them locally with: npm run benchmarks.

Running inside Docker (Alpine Linux v3.10) with Node v12.10.0 and Intel(R) Core(TM) i7-3537U CPU @ 2.00GHz x 4

Testing:
- async     v3.1.0 https://caolan.github.io/async/         
- neo-async v2.6.1 https://github.com/suguru03/neo-async   
- waitron   v2.0.0 https://github.com/ahwayakchih/waitron  

Test with 0 holders

  3 tests completed.

  neo-async x 337,702 ops/sec ±1.03% (77 runs sampled)
  waitron   x 323,296 ops/sec ±1.26% (74 runs sampled)
  async     x 309,637 ops/sec ±1.72% (76 runs sampled)

Test with 5 holders

  3 tests completed.

  neo-async x 225,758 ops/sec ±1.36% (80 runs sampled)
  waitron   x 188,512 ops/sec ±1.24% (74 runs sampled)
  async     x 183,181 ops/sec ±1.61% (76 runs sampled)

Test with 15 holders

  3 tests completed.

  neo-async x 130,311 ops/sec ±1.40% (76 runs sampled)
  waitron   x 121,419 ops/sec ±1.48% (74 runs sampled)
  async     x 101,664 ops/sec ±1.73% (78 runs sampled)

Test with 29 holders

  3 tests completed.

  neo-async x 82,468 ops/sec ±1.18% (79 runs sampled)
  waitron   x 76,747 ops/sec ±1.46% (73 runs sampled)
  async     x 63,677 ops/sec ±1.87% (79 runs sampled)