node-process-pool
Version:
a process pool for Node.js
35 lines (29 loc) • 996 B
Markdown
### Node Process Pool
**If you want to learn more, please visit [ProcessPool]( https://github.com/GeniusFunny/ProcessPool) in github.**
#### Installation
```bash
npm install node-process-pool
```
#### Usage
```js
// Process pool usage example
const ProcessPool = require('node-process-pool')
const taskParams = []
for (let i = 0; i < 5000; i++) {
taskParams[i] = [i]
}
// Create a process pool instance
const processPool = new ProcessPool({
maxParallelProcess: 50, // Supports maximum number of process parallelism
timeToClose: 60 * 1000, // The maximum time for a single task to be executed
dependency: `const path = require('path')`, // task script dependencies
workDir: __dirname, // current directory
taskName: 'test', // task script name
script: async function task(taskParams) {
console.log(taskParams)
},
taskParams // Need to perform the task parameter list, two-dimensional array
})
// Process pools are used to handle large scale tasks
processPool.run()
```