Git Product home page Git Product logo

Comments (5)

josdejong avatar josdejong commented on July 17, 2024 1

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'. When force is true, all workers are terminated immediately without finishing running tasks. If timeout 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.

RewriteH avatar RewriteH commented on July 17, 2024

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'. When force is true, all workers are terminated immediately without finishing running tasks. If timeout 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

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.

josdejong avatar josdejong commented on July 17, 2024

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.

Darshan-upadhyay1110 avatar Darshan-upadhyay1110 commented on July 17, 2024

await pool.completed().then(result=>{ await pool.terminate(); })
is it the way we can do this ?

from workerpool.

josdejong avatar josdejong commented on July 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.