josdejong / workerpool

Offload tasks to a pool of workers on node.js and in the browser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

cha0s opened this issue · comments

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:

Anyone able to work this out in a PR?

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!

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