Created
October 15, 2020 10:50
-
-
Save Terkea/a582fb21d4c832edbb3690c596a3cc0e to your computer and use it in GitHub Desktop.
que system node js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function (inp, callback) { | |
setTimeout(() => { | |
callback(null, inp); | |
}, 3000); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var workerFarm = require('worker-farm'); | |
const FARM_OPTIONS = { | |
maxConcurrentWorkers: 2, | |
maxConcurrentCallsPerWorker: 1 | |
} | |
var task = workerFarm(FARM_OPTIONS, require.resolve('./child')); | |
var workers = 0; | |
for (var i = 0; i < 10; i++) { | |
task('#' + i + ' FOO', function (err, outp) { | |
console.log(outp) | |
if (++workers == 10) | |
workerFarm.end(task) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment