Last active
June 4, 2020 06:52
-
-
Save velotiotech/1f7ade9f3581a6202269151d056eaad7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async.parallel([ | |
function(callback) { | |
setTimeout(function() { | |
console.log('Task One'); | |
callback(null, 1); | |
}, 200); | |
}, | |
function(callback) { | |
setTimeout(function() { | |
console.log('Task Two'); | |
callback(null, 2); | |
}, 100); | |
} | |
], | |
function(err, results) { | |
console.log(results); | |
// the results array will equal [1, 2] even though | |
// the second function had a shorter timeout. | |
}); | |
// an example using an object instead of an array | |
async.parallel({ | |
task1: function(callback) { | |
setTimeout(function() { | |
console.log('Task One'); | |
callback(null, 1); | |
}, 200); | |
}, | |
task2: function(callback) { | |
setTimeout(function() { | |
console.log('Task Two'); | |
callback(null, 2); | |
}, 100); | |
} | |
}, function(err, results) { | |
console.log(results); | |
// results now equals to: { task1: 1, task2: 2 } | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment