josdejong/workerpool

Add completed method in Pool

オープン

#354 opened on 2022/09/08

 (5 件のコメント) (0 件のリアクション) (0 人の担当者)JavaScript (164 件のフォーク)github user discovery
enhancementhelp wanted

Repository metrics

Stars
 (2,307 個のスター)
PR merge metrics
 (平均マージ 21d 16h) (30d で 3 merged PRs)

説明

Instead of doing every time this:

const pool = workerpool.pool(
    path.resolve(__dirname, 'worker')
)
const tasks: workerpool.Promise<any, Error>[] = []

for (const entity of entities) {
 const task = pool.exec('worker', [entity])
 tasks.push(task)
}

await Promise.all(tasks)
await pool.terminate()

We can do:

const pool = workerpool.pool(
    path.resolve(__dirname, 'worker')
)

for (const entity of entities) {
 pool.exec('worker', [entity])
}

/* Wait all tasks to complete */ 
await pool.completed()
await pool.terminate()

It would be very handy, if this method is added in the future For example, threads.js already have this feature

コントリビューターガイド