var async = require('async');
async.parallel([
function(cb) {
cb(true);
},
function(cb) {
cb(null, true);
}],
function(error, results) {
}
);
In the code, if the first task runs cb(true) before the second tasks, will the second tasks still run? and If so, after it is done, will the main callback still be called?
Asynchronous operations in parallel The first argument to async. parallel() is a collection of the asynchronous functions to run (an array, object or other iterable). Each function is passed a callback(err, result) which it must call on completion with an error err (which can be null ) and an optional results value.
async. eachSeries() applies an asynchronous function to each item in an array in series. For example, say you have a list of users, each of which needs to post its profile data to remote server log. Order matters in this case because the users in your array are sorted.
The async. waterfall allows each function to pass on its results to the next function, while async. series passes all the task's results to the final callback.
Below are the two arguments that async. queue takes as input: Task Function. Concurrency Value.
yes, second task is called (because tasks are expected to be async and exit immediately). async.parallel
callback is called with error from first failed task
The async.parallel
executes all functions in parallel. If any of the functions pass an error to its callback (callback first parameter is not null), the main callback is immediately called with the value of the error. All functions will be executed though.
With the following code your execution will be as follows 1, 3, 2, 2.1
:
var async = require('async');
async.parallel([
function(cb) {
console.info('1')
cb(true);
},
function(cb) {
console.info('2')
cb(null, true);
},
function(cb) {
console.info('2.1')
cb(null, true);
}],
function(error, results) {
console.info('3')
}
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With