josdejong/workerpool

Add completed method in Pool

Open

#354 geöffnet am 8. Sept. 2022

Auf GitHub ansehen
 (5 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)JavaScript (164 Forks)github user discovery
enhancementhelp wanted

Repository-Metriken

Stars
 (2.297 Stars)
PR-Merge-Metriken
 (PR-Metriken ausstehend)

Beschreibung

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

Contributor Guide