exec-queue
Version:
Safely run exec in a loop.
34 lines (27 loc) • 673 B
JavaScript
// Generated by CoffeeScript 1.6.3
(function() {
var MAX_PROCS, exec, nextInLine, queue;
MAX_PROCS = 10;
exec = require('child_process').exec;
queue = [];
nextInLine = function() {
if (queue.length > 0) {
return exec.apply(null, queue.shift());
}
};
module.exports = function() {
var args, oldCb;
args = Array.prototype.slice.call(arguments);
oldCb = args.pop();
args.push(function() {
oldCb.apply(null, arguments);
return nextInLine();
});
queue.push(args);
if (queue.length < MAX_PROCS) {
return process.nextTick(function() {
return nextInLine();
});
}
};
}).call(this);