Gracefully kill a worker, making sure it terminates in either case.
// worker.jsparentPort.on'message',// main.js// ... after we don't need the worker anymoretrycatch err
npm install kill-worker
/*** Kills a worker.* First gracefully by sending the provided message so it can exit itself* via `process.exit`.* If worker doesn't comply and exit within the given `timeoutMs` it is terminated* via `worker.terminate`.** @param worker the worker to kill* @param killMsg the message to send to the worker to comply and exit itself* @param timeoutMs timeout in milliseconds after which worker is forcefully terminated* @return a promise which resolves if worker exits non-zero and rejects if worker exits* non-zero. When worker needs to be terminated the exit code will be non-zero as well.*/