josdejong/workerpool

Add completed method in Pool

開放

#354 建立於 2022年9月8日

 (5 則留言) (0 個反應) (0 位負責人)JavaScript (164 個分叉)github user discovery
enhancementhelp wanted

倉庫指標

星標
 (2,307 顆星)
PR 合併指標
 (平均合併 21天 16小時) (30 天內合併 3 個 PR)

描述

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

貢獻者指南