Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terminating worker threads - the correct way ? #196

Open
iangregsondev opened this issue Feb 6, 2019 · 0 comments
Open

Terminating worker threads - the correct way ? #196

iangregsondev opened this issue Feb 6, 2019 · 0 comments

Comments

@iangregsondev
Copy link

Hi,

I have a scheduler (every 30 seconds) that calls my worker (which sets up a worker) - I am confused when i should be terminating the thread or the worker.

Is the correct way to terminate the thread or terminate the worker i.e

    this.thread.destroy()

vs

    workerHandler.terminate()

I have the following, I am monitoring the threadId and its incrementing all the time. I am worried about a memory leak or the id of thread maxing out.

Any ideas ? Thanks in advance

export const worker = (redisClient: RedisClient) => {
  const workerHandler = new Worker(function() {
    this.postMessage({ finished: true })
    this.thread.destroy()
  })

  workerHandler.onmessage = (event: Event): void => {
    if (event.data.finished === true) {
      workerHandler.terminate()
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant