josdejong / workerpool

Offload tasks to a pool of workers on node.js and in the browser
Apache License 2.0
2.04k stars 148 forks source link

`worker.exit` should set `process.exitCode` instead of calling `process.exit` to allow cleanup #429

Open cha0s opened 6 months ago

josdejong commented 6 months ago

Ahh, I was not aware of that. Who knows, this may explain some of the issues regarding exiting that we've seen in the past.

For context:

josdejong commented 6 months ago

Anyone able to work this out in a PR?

cha0s commented 6 months ago

Just as a little context, I encountered this library when working with mocha --parallel which uses workerpool to handle its workers.

This is what I came up with for the mean time to reliably(?) run cleanup tasks from within a worker:

  process.prependListener('message', async (message) => {
    if ('__workerpool-terminate__' === message) {
      // ...
    }
  });

I might be able to get a PR on this soonish, but I would definitely want to familiarize myself a little more with the code than the quick spelunk that led me to bring this issue to your attention.

Thanks for the response!

josdejong commented 6 months ago

Thanks for the clarification Ruben! Help working this out in a solution would be very welcome.