spawn-limit
v1.2.0
Published
child_process.spawn with process count limit
Downloads
244
Readme
spawn-limit
It is almost as same as original child_process.spawn
, but it has maximum process number limit.
spawn
function receives compatible arguments of child_process.spawn
, but it returns a Promise object instead of process instance.
This promise is triggered when the process is actually spawned. It passes process instance to the promise callback function.
var spawn = require("spawn-limit").spawn;
var promise = spawn("ls", ["-la"], {cwd: "~"});
promise.then(function (ls) {
ls.stdout.on("data", function (data) {
console.log(data.toString());
});
ls.on("close", function (code) {
console.log("code:", code);
});
});
This module provides setLimit()
function to set limit count of process, and `waitAll()`` for waiting all external processes's terminations.
var sl = require("spawn-limit");
sl.setLimit(10);
logFiles.map(function (logFile) {
sl.spawn("cp", [logFile, "/var/log/archive"]);
});
API
- spawn(cmd, [args], [options) => promise
Spawn esternal process.
- setLimit(num)
Set limit count of process. Default number is 10.
- waitAll() => promise
Wait all external process's termination.
License
MIT License