ruk·si

🟢 Node
Async Queue

Updated at 2013-07-04 09:04
var async = require('async');

function worker(data, callback) {
    console.log('start: ' + data);
    setTimeout(function() {
        console.log('end: ' + data);
        callback();
    }, 250);
}

var concurrency = 2;
var queue = async.queue(worker, concurrency);
queue.push(1);
queue.push(2);
queue.push(3);
queue.push(4);
queue.push(5);
start: 1
start: 2
end: 1
start: 3
end: 2
start: 4
end: 3
start: 5
end: 4
end: 5

Sources

  • Async JS