offscreen-canvas icon indicating copy to clipboard operation
offscreen-canvas copied to clipboard

How to terminate the worker?

Open rssfrncsrenishaw opened this issue 5 years ago • 6 comments

How to terminate the worker? The API that is returned by both createWorker and insideWorker does not include terminate.

rssfrncsrenishaw avatar May 13 '20 11:05 rssfrncsrenishaw

Maybe the following?

// worker
terminate: function() {
  worker.terminate();
}

// fallback
terminate: function() {
  document.head.removeChild(script);
  window[randomId] = undefined;
}

rssfrncsrenishaw avatar May 13 '20 11:05 rssfrncsrenishaw

Note sure that fallback will work in all of the cases

ai avatar May 13 '20 12:05 ai

@ai okay that's fine but do you think this is something you would be happy to support? Termination is rather important in cases where workers are tied to the life of something potentially short lived such as a React component.

rssfrncsrenishaw avatar May 14 '20 06:05 rssfrncsrenishaw

@rssfrncsrenishaw honestly, this library is just an example for the article :)

ai avatar May 14 '20 06:05 ai

@ai haha actually I didn't arrive at this repo from an article and skipped straight past the intro to the "usage" section... Just had a look at the article :)

Do you think this is fine for production? It's working well for me.

Are you happy for PRs or would you rather people just forked for their own requirements?

rssfrncsrenishaw avatar May 14 '20 06:05 rssfrncsrenishaw

Do you think this is fine for production? It's working well for me.

Yeap.

Are you happy for PRs or would you rather people just forked for their own requirements?

I will accept and release PR. It is a real project anyway.

ai avatar May 14 '20 06:05 ai