Queueing is a queueing library for the synchronized execution of asynchronous functions. It is a non-blocking library. Relative XKCD.
Note: this is a lightweight library, check out Kue for a more heavyweight alternative.
$ npm install queueing --save
var queueing = require('queueing');
var queue = queueing.init({
// The delay to be ran between each task
delayBetweenTasks: 1000
});
This function takes an object as its parameter. This object contains all the options for the queue. All the options are optional.
This assumes you already have initiated a queue.
queue.pushTask(function(done) {
// What I want to do in my task
fs.doSomething('my/file', function() {
done();
});
});
Simply supply a function to pushTask
that will be executed in the queue. You must call done()
when you are finished, otherwise the queue will not be able to continue execution.
Again, assumes you have already initiated a queue.
queue.pushTasks([function(done) {
// Do things
done();
}, function(done) {
// Do more things
done();
}, function(done) {
// Do my last things
done();
}]);
This is a bulk pushTask
alternative. It takes a single array as a parameter. The array contains multiple functions, ordered in their execution line.
queue.stop();
This stops the queue immediately after the present task is finished executing. If there is no task executing, it will be stopped immediately.