"Lifts" a regular old synchronous function into the wondrous world of async.

Why would you ever want to make more functions async then you have to? Well, imagine you were using async.waterfall to get fetch some data asynchronously, transform it synchronously, and send it off somewhere else asynchronously. Your code might look like this:

async.waterfall [

fetchData

(data, cb)->

try

data = transform data

sendData data, cb

catch err

setImmediate -> cb err

], errHandler

With async.lift, you can write that like this:

async.waterfall [

fetchData

async.lift (data)-> transform data

sendData

], errHandler

async.lift takes a synchronous function and returns an asynchronous version of that function that applies its callback to any results returned by the original function.

The input function may accept any number of arguments - the resulting function will as well. If the input function returns a single value, the callback will be called with that value. If the input function returns an array, the callback will be applied to the array.

Any errors thrown by the input function will be caught and passed to the callback. If no error is thrown, the callback will be called with null as the error argument.

The resulting function will call its callback using setImmediate, to prevent releasing the Zalgo.

Lifts a synchronous function but ignores its return value, instead passing along whatever arguments it receives. This can be useful for inserting functions into pipelines when you only care about their side effects.

For example, we can insert some logging statements into our previous waterfall without having to modify any of the preexisting code:

async.waterfall [

fetchData

async.lift (data)-> transform data

async.tap (data)->console.log'got some data', data

sendData # is called with the same data as the logging function

async.tap ->console.log'done sending!'

], errHandler

Any errors thrown by the input function will be caught and passed to the callback. If no error is thrown, the callback will be called with null as the error argument.

Like _.once, takes an asynchronous function and returns a version of the function that will only run once. Subsequent calls to the function will call the given callback with the same results that were passed to the callback of the first invocation.

If the function is called multiple times, the callbacks will be called in the order of the invocations.

Takes a condition, two functions, and a callback. If the condition evaluates to true, then_fn will be called, else else_fn will be. Both will be given cb as a callback. This allows you to define the callback at the same time as the functions, improving readability.

Takes an object, an async function, and a final callback. async.mapValues creates a new object whose values are the results of applying the function to each key/value pair of the original object. The resulting object is passed to the final callback.

If the function calls its callback with an error, it will short-circuit the computation and pass the error to the final callback.