I want to restrict the number of calls to be made to exec command. I checked Promise.map API which goes as below :
Promise.map(
Iterable<any>|Promise<Iterable<any>> input,
function(any item, int index, int length) mapper,
[Object {concurrency: int=Infinity} options]
) -> Promise
I want to use it to limit the number of exec command called and all other call beyong the limit to wait until concurrency level goes below the limit. So basically the below program will keep on calling exec and thus forking native process. I want to limit the number of native process to be forked. Hence I need to keep any request to call to exec beyond a limit N to be in blocked state until, promise map can take new task. This is similar to blocking queue implementation in java.
app.post('/upload',function(req,res){
upload(req,res,function(err) {
if(err) {
return res.end("Error uploading file.");
}
console.log("Coverting to PDF");
var inputfile = "./uploads/" + req.file.filename;
var outfile = "./exports/" + req.file.filename + ".pdf";
var command = '"sample.exe"' + " \"" + inputfile + "\" " + "\"" + outfile + "\"" ;
console.log(command);
/*I want to limit the call to below code to some number N and all N+1 calls to wait until the number of native execution goes below N*/
exec(command,(error, stdout, stderr) => {
console.log("trying to download file " + outfile);
res.download(outfile);
});
console.log("Coversion Done");
});
});