Skip to content

The question about the example? #5

@chengdonglin

Description

@chengdonglin

Some question about the example? the example you give the tasks to run by thread pool, if the tasks number is dynamic, how to resolve this problem? The following code:

const Pool = require('worker-threads-pool')
const pool = new Pool({max: 5})
const tasks=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]
for (let i = 0; i < tasks.length; i++) {
pool.acquire('./worker.js',{workerData:tasks[i]}, function (err, worker) {
if (err) throw err
console.log(started worker ${i} (pool size: ${pool.size}))
worker.on('exit', function () {
console.log(worker ${i} exited (pool size: ${pool.size}))
})
})
}
console.log("main thread")

thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions