Global

Type Definitions

AsyncFunction()

An "async function" in the context of Async is an asynchronous function with a variable number of parameters, with the final parameter being a callback. (function (arg1, arg2, ..., callback) {}) The final callback is of the form callback(err, results...), which must be called once the function is completed. The callback should be called with a Error as its first argument to signal that an error occurred. Otherwise, if no error occurred, it should be called with null as the first argument, and any additional result arguments that may apply, to signal successful completion. The callback must be called exactly once, ideally on a later tick of the JavaScript event loop.

This type of function is also referred to as a "Node-style async function", or a "continuation passing-style function" (CPS). Most of the methods of this library are themselves CPS/Node-style async functions, or functions that return CPS/Node-style async functions.

Wherever we accept a Node-style async function, we also directly accept an ES2017 async function. In this case, the async function will not be passed a final callback argument, and any thrown error will be used as the err argument of the implicit callback, and the return value will be used as the result value. (i.e. a rejected of the returned Promise becomes the err callback argument, and a resolved value becomes the result.)

Note, due to JavaScript limitations, we can only detect native async functions and not transpilied implementations. Your environment must have async/await support for this to work. (e.g. Node > v7.6, or a recent version of a modern browser). If you are using async functions through a transpiler (e.g. Babel), you must still wrap the function with asyncify, because the async function will be compiled to an ordinary function that returns a promise.

Source: