🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

async-settle

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-settle

Settle an async function.

1.0.0
Source
npm
Version published
Weekly downloads
1.5M
-4.78%
Maintainers
1
Weekly downloads
 
Created
Source

async-settle

NPM version Downloads Build Status AppVeyor Build Status Coveralls Status Gitter chat

Settle an async function. It will always complete successfully with an object of the resulting state.

Handles completion and errors for callbacks, promises, observables and streams.

Will run call the function on nextTick. This will cause all functions to be async.

Usage

Successful completion

var asyncSettle = require('async-settle');

asyncSettle(function(done){
  // do async things
  done(null, 2);
}, function(error, result){
  // `error` will ALWAYS be null on execution of the first function.
  // `result` will ALWAYS be a settled object with the result or error of the first function.
});

Failed completion

var asyncSettle = require('async-settle');

asyncSettle(function(done){
  // do async things
  done(new Error('Some Error Occurred'));
}, function(error, result){
  // `error` will ALWAYS be null on execution of the first function.
  // `result` will ALWAYS be a settled object with the result or error of the first function.
});

API

asyncSettle(fn, callback)

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

fn([done])

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

Executed in the context of async-done, with all errors and results being settled.

Completion is handled by async-done completion and error resolution.

callback(error, result)

Called on completion of fn and recieves a settled object as the result argument.

The error argument will always be null.

Settled Object

Settled values have two properties, state and value.

state has two possible options 'error' and 'success'.

value will be the value passed to original callback.

License

MIT

Keywords

settle

FAQs

Package last updated on 26 Jun 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts