| Start |
|---|
| Parallel : multi-tasking async.parallel(tasks, afterTasksCallback) (opens new window) will execute a set of tasks in parallel and wait the end of all tasks (reported by the call of callback function). When tasks are finished, async call the main callback with all errors and all results of tasks. Result : Call |
| Series : independent mono-tasking async.series(tasks, afterTasksCallback) (opens new window) will execute a set of tasks. Each task are executed after another. If a task fails, async stops immediately the execution and jump into the main callback. When tasks are finished successfully, async call the "master" callback with all errors and all results of tasks. Result : Call |
| Waterfall : dependent mono-tasking async.waterfall(tasks, afterTasksCallback) (opens new window) will execute a set of tasks. Each task are executed after another, and the result of a task is passed to the next task. As async.series(), if a task fails, async stop the execution and call immediately the main callback. When tasks are finished successfully, async call the "master" callback with all errors and all results of tasks. Result: |
| async.each(To handle array of data efficiently) When we want to handle array of data, its better to use async.each. When we want to perform something with all data & want to get the final callback once everything is done, then this method will be useful. This is handled in parallel way. To do one at a time can use async.eachSeries |
| async.times(To handle for loop in better way) To execute a function within a loop in node.js, it's fine to use a This is called in parallel. When we want to call it one at a time, use: async.timesSeries |
| async.series(To handle events one by one) /In async.series,all the functions are executed in series and the consolidated outputs of each function is passed to the final callback. e.g/ var async = require('async'); async.series([ function (callback) { console.log('First Execute..'); callback(null, 'userPersonalData'); }, function (callback) { console.log('Second Execute.. '); callback(null, 'userDependentData'); } ], function (err, result) { console.log(result); }); //Output: First Execute.. Second Execute.. ['userPersonalData','userDependentData'] //result Syntax |
Read Article
https://develop.horje.com/learn/1434/reference