Last active
December 18, 2015 07:19
-
-
Save coffeesam/5745973 to your computer and use it in GitHub Desktop.
queue-async sample
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
var queue = require('queue-async'); | |
var q = queue(1); // one concurrent task | |
// Queue 2 task and define completion call back | |
q.defer(setTimeout, function(callback) { console.log('job 1'); callback(null);}, 1000) | |
.defer(setTimeout, function(callback) { console.log('job 2'); callback(null); }, 1000) | |
.awaitAll(function(error, results) { console.log('all done!'); } ); | |
// Queue 2 more tasks before completion kicks in | |
q.defer(setTimeout, function(callback) { console.log('job 3'); callback(null);}, 1000); | |
q.defer(setTimeout, function(callback) { console.log('job 4'); callback(null);}, 1000); | |
// Add a task with a param | |
q.defer(setTimeout, function(param, callback) { console.log(param + ' job 3'); callback(null); }, 1000, 'Now running:'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment