josdejong / josdejong/workerpool
Add completed method in Pool
- Dominant language
- JavaScript
- Stars
- 2.3k
- Forks
- 164
- PR merge metrics
- No merged PRs in 30d
Description
Instead of doing every time this:
```
const pool = workerpool.pool(
path.resolve(__dirname, 'worker')
)
const tasks: workerpool.Promise[] = []
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](https://threads.js.org/usage-pool#waiting-for-tasks-to-complete)
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.