I saw a code that looks like this (Pro Node). It uses async
library.
var async = require("async");
async.series([
function(callback) {
setTimeout(function() {
console.log("Task 1");
callback(null, 1);
}, 300); },
function(callback) {
setTimeout(function() {
console.log("Task 2");
callback(null, 2);
}, 200);
},
function(callback) {
setTimeout(function() {
console.log("Task 3");
callback(null, 3);
}, 100); }
], function(error, results) {
console.log(results);
});
When I run it, it shows:
Task 1
Task 2
Task 3
[ 1, 2, 3 ]
All is well - however, I do not quite understand what the callback lines are: callback(null, 1)
, callback(null, 2)
, and callback(null, 3)
.
If I remove all of those lines, when I run the code it returns only:
Task 1
What do the first and second arguments do and why are the second arguments 1
, 2
, and 3
?