0.6.0 • Published 5 years ago

node-workerthread-pool v0.6.0

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

Node.js Thread Pool

📦 Install

npm install node-workerthread-pool

🔨Usage

const fs = require('fs')
const ThreadPool = require('node-thread-pool')
const taskParams = []
for (let i = 0; i < 1000; i++) {
  taskParams[i] = [i]
}
const threadPool = new ThreadPool({
  maxParallelThread: 50,
  timeToClose: 60 * 1000,
  dependency: `const fs = require('fs')`,
  workDir: __dirname,
  taskName: 'writeNumber',
  script: async function task(workParam) {
    try {
      let start = Date.now()
      while (Date.now() < start + 200) {}
      fs.appendFileSync(`${__dirname}/numbers.txt`, `${workParam[0]}\n`)
    } catch (e) {
      console.log(e)
    }
  },
  taskParams
})
threadPool.run()

🤝贡献 PRs Welcome

I welcome all contributions. You can submit any ideas as pull requests or as GitHub issues. If you'd like to improve code, please create a Pull Request.