Created
October 14, 2012 15:16
-
-
Save mrlannigan/3888877 to your computer and use it in GitHub Desktop.
async queue callback test
This file contains hidden or 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 async = require('async'), concurrency = 1, i, timestart = Date.now(); | |
var testQueue = async.queue(function(task, callback) { | |
var _runonce = false; | |
console.log('running number '+task.number+', time: '+(Date.now() - timestart)); | |
var cb = function() { | |
if (_runonce) return; | |
/* | |
Uncomment this line to show the difference between running the callback | |
only once and multiple times. | |
*/ | |
//_runonce = true; | |
callback(); | |
} | |
setTimeout(function() { | |
if (task.number == 2 || task.number == 10) { | |
cb(); | |
cb(); | |
} else { | |
cb(); | |
} | |
}, 1000); | |
}, concurrency); | |
testQueue.saturated = function() { | |
console.log('testQueue: is saturated'); | |
} | |
testQueue.empty = function() { | |
console.log('testQueue: is now empty'); | |
} | |
testQueue.drain = function() { | |
console.log('testQueue: has finished processing all queued tasks'); | |
} | |
for (i = 0; i <= 20; i++) { | |
testQueue.push({number: i}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment