Big update!Introducing GitHub Bot Commands. Learn more
Socket
Log inBook a demo

async-done

Package Overview
Dependencies
3
Maintainers
2
Versions
17
Issues
File Explorer

Advanced tools

async-done

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

    2.0.0latest

Version published
Maintainers
2
Weekly downloads
1,375,863
increased by15.17%

Weekly downloads

Changelog

Source

2.0.0 (2022-06-25)

⚠ BREAKING CHANGES

  • Allow end-of-stream to handle the stream error states
  • Normalize repository, dropping node <10.13 support (#54)

Bug Fixes

  • Allow end-of-stream to handle the stream error states (7b37da4)
  • Ensure the Observable failure test works (#59) (dfa4f0b)

Miscellaneous Chores

  • Normalize repository, dropping node <10.13 support (#54) (66f987f)

Readme

Source

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

Keywords

FAQs

What is async-done?

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

Is async-done popular?

The npm package async-done receives a total of 1,107,535 weekly downloads. As such, async-done popularity was classified as popular.

Is async-done well maintained?

We found that async-done demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 2 open source maintainers collaborating on the project.

Last updated on 25 Jun 2022

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc