In the Async module, log(function)
logs the result of an async function to the console.
If multiple arguments are returned from the async function, console.log
is called on each argument in order.
log(function)
only works in Node.js or in browsers that supportconsole.log
andconsole.error
.
async.log(function, arguments...)
function
: An AsyncFunction that you eventually want to apply all arguments to.arguments...
: Any number of arguments to apply to the function.In this example, we are creating a simple async function (called hello
) that takes the argument name
and a callback function.
We then use log(hello, 'world')
to log the results of the hello function with the argument name='world'
.
import log from 'async/log';// A simple AsyncFunction that prints// Hello after a certain timeoutvar hello = function(name, callback) {setTimeout(function() {callback(null, 'hello ' + name);}, 1000);};// Using async.log to log the result of// hello function to the consolelog(hello, 'world');