ai / offscreen-canvas

Polyfill for OffscreenCanvas to move Three.js/WebGL/2D canvas to Web Worker
MIT License
332 stars 13 forks source link

How to terminate the worker? #12

Open rssfrncsrenishaw opened 4 years ago

rssfrncsrenishaw commented 4 years ago

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

rssfrncsrenishaw commented 4 years ago

Maybe the following?

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

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

Note sure that fallback will work in all of the cases

rssfrncsrenishaw commented 4 years ago

@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.

ai commented 4 years ago

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

rssfrncsrenishaw commented 4 years ago

@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?

ai commented 4 years ago

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.