Comments (5)
Thanks for your suggestion. Actually, what you want is already there: just calling await pool.terminate()
will by default gracefully shutdown the workerpool. It finishes all running tasks and does not accept new tasks.
From the docs:
Pool.terminate([force: boolean [, timeout: number]])
If parameter
force
is false (default), workers will finish the tasks they are working on before terminating themselves. Any pending tasks will be rejected with an error 'Pool terminated'. Whenforce
is true, all workers are terminated immediately without finishing running tasks. Iftimeout
is provided, worker will be forced to terminate when the timeout expires and the worker has not finished.
Docs: https://github.com/josdejong/workerpool#api
from workerpool.
Thanks for your suggestion. Actually, what you want is already there: just calling
await pool.terminate()
will by default gracefully shutdown the workerpool. It finishes all running tasks and does not accept new tasks.From the docs:
Pool.terminate([force: boolean [, timeout: number]])
If parameterforce
is false (default), workers will finish the tasks they are working on before terminating themselves. Any pending tasks will be rejected with an error 'Pool terminated'. Whenforce
is true, all workers are terminated immediately without finishing running tasks. Iftimeout
is provided, worker will be forced to terminate when the timeout expires and the worker has not finished.
Wow, i tried. But it works not as expected. In this code pool terminated first. Tasks not executing.
const pool = workerpool.pool(
path.resolve(__dirname, 'worker')
)
for (const entity of entities) {
pool.exec('worker', [entity])
}
await pool.terminate()
from workerpool.
Ooo wait a second, of course: terminate
only gracefully finishes all running tasks, but it will cancel and not execute queued tasks. Sorry, my bad.
So, yes, your suggestion makes sense, a method like await pool.completed()
. Anyone interested in thinking this through and implementing such a method?
from workerpool.
await pool.completed().then(result=>{ await pool.terminate(); })
is it the way we can do this ?
from workerpool.
Yes, you can keep track on all tasks and wait till they are all resolved, like the first example in #354 (comment). It's a bit cumbersome but not a showstopper.
from workerpool.
Related Issues (20)
- Task's error is being resolved HOT 3
- require is not defined on .exec function HOT 7
- Anyone able to get workerpool to work on Vite? HOT 19
- Create an ES module version of workerpool.js HOT 1
- TypeError: Cannot read properties of undefined (reading 'push') HOT 1
- Working with typescript causing an error: The worker script extension must be \".js\", \".mjs\", or \".cjs\". Received \".ts\" HOT 3
- Does workerpool support offload JavaScript between devices (e.g., from mobile to server workerpool) HOT 1
- Sharing streams with workers from the main thread HOT 5
- How to pass a callback function to "OnCreateWorker" method? HOT 1
- How to pass a callback function to `onCreateWorker` method? HOT 8
- Allow main thread to cleanly cancel workers HOT 4
- Using wokerpool on multi node.js processes running on the same server HOT 1
- support worker execArgv HOT 2
- Fix the code coverage script HOT 1
- App bundle fails to start worker, with message : "Worker is terminated" HOT 1
- Type of error is not kept when error goes from inside to outside the workerpool HOT 1
- Uncaught SyntaxError: Unexpected token '<' (at worker.ts:1:1) HOT 1
- Send event / message to running Worker? HOT 11
- Concurrent async tasks on a single worker HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from workerpool.