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

ondone

v1.0.0

Published

Wait for one or more async functions to be done.

Downloads

28,934

Readme

ondone

Wait for one or more async functions to be done.

Installation

npm install --save ondone

API

var ondone = require('ondone');
tasks = ondone(tasks, doneFn);

ondone accepts an array of tasks and a done function (doneFn). It returns an array of functions that can be passed to any async execution engine (like miniq or async.js). It adds the following functionality:

  • once all of the tasks have completed, the done function is called (with no error or result argument)
  • if any of the tasks returns an error:
    • the done function is called with the error
    • the other tasks passed in the same array will be cancelled (will become no-ops)
  • if the done function to any callback is called twice, an error is thrown

In short, this is "waiting for tasks to complete" portion of async execution without the actual task execution logic. It helps keep async runners smaller (ondone is ~1000 bytes unminified) while allowing them to support more flexible task batching.

Tasks are callbacks that have a signature such as:

  • function(done) {}
  • function(arg1, done) {}
  • function(arg1, arg2, ..., done)

that is, the last argument to each task must be a done function. The done function should accept an err (error) parameter as it's first argument, and may have additional arguments after the err argument, e.g.:

  • function done(err) {}
  • function done(err, arg) {}
  • function done(err, arg1, arg2, ...) {}

Example

Here, I'm taking a set of tasks and dividing it into two sets of tasks. When each set of tasks completes, the done function for that set is called:

var completedFirst = false,
    completedSecond = false;
async.waterfall(
    ondone([
      function(callback){ callback(null, 'one', 'two'); },
      function(arg1, arg2, callback){ callback(null, arg1 + arg2 + 'three');}
      ], function() { completedFirst = true; })
    .concat(
      ondone([
        function(arg1, callback){ callback(null, arg1 + 'done'); }
      ], function() { completedSecond = true; }))
  , function (err, result) {
  assert.equal(result, 'onetwothreedone');
  assert.ok(completedFirst);
  assert.ok(completedSecond);
});

Related

  • https://github.com/ifit/waitress
  • https://github.com/eldargab/asyncloop
  • https://github.com/stagas/waits
  • https://github.com/taoyuan/cancelify
  • https://github.com/socialradar/hold
  • https://github.com/adamhalasz/nextjs
  • https://github.com/KoryNunn/wait-for