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

async-done

v2.0.0

Published

Allows libraries to handle various caller provided asynchronous functions uniformly. Maps promises, observables, child processes and streams, and callbacks to callback style.

Downloads

6,557,263

Readme

async-done

NPM version Downloads Build Status Coveralls Status

Allows libraries to handle various caller provided asynchronous functions uniformly. Maps promises, observables, child processes and streams, and callbacks to callback style.

As async conventions evolve, it is useful to be able to deal with several different styles of async completion uniformly. With this module you can handle completion using a node-style callback, regardless of a return value that's a promise, observable, child process or stream.

Usage

Successful completion

var asyncDone = require('async-done');

asyncDone(
  function (done) {
    // do async things
    done(null, 2);
  },
  function (error, result) {
    // `error` will be null on successful execution of the first function.
    // `result` will be the result from the first function.
  }
);

Failed completion

var asyncDone = require('async-done');

asyncDone(
  function (done) {
    // do async things
    done(new Error('Some Error Occurred'));
  },
  function (error, result) {
    // `error` will be an error from the first function.
    // `result` will be undefined on failed execution of the first function.
  }
);

API

asyncDone(fn, callback)

Takes a function to execute (fn) and a function to call on completion (callback).

fn([done])

Optionally takes a callback to call when async tasks are complete.

Completion and Error Resolution

  • Callback (done) called
    • Completion: called with null error
    • Error: called with non-null error
  • Stream or EventEmitter returned
    • Completion: end-of-stream module
    • Error: domains
    • Note: Only actual streams are supported, not faux-streams; Therefore, modules like event-stream are not supported.
  • Child Process returned
  • Promise returned
  • Observable (e.g. from RxJS v5 or RxJS v4) returned

Warning: Sync tasks are not supported and your function will never complete if the one of the above strategies is not used to signal completion. However, thrown errors will be caught by the domain.

callback(error, result)

If an error doesn't occur in the execution of the fn function, the callback method will receive the results as its second argument. Note: Some streams don't received any results.

If an error occurred in the execution of the fn function, The callback method will receive an error as its first argument.

Errors can be caused by:

  • A thrown error
  • An error passed to a done callback
  • An error event emitted on a returned Stream, EventEmitter or Child Process
  • A rejection of a returned Promise - If the Promise is not rejected with a value, we generate a new Error
  • The onError handler being called on an Observable

License

MIT