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.