Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Destroying WebWorkers

Is there a way to destroy HTML5 WebWorkers in JavaScript?

Here's my situation: I have a web application that generates a decent number of WebWorkers (anywhere between 16 and 32) to optimize some rendering processes. This process works fine the first few times through, but the page dies when the script is run several times (without reloading the page). It's the same error I get when I try to spawn a lot (100+) WebWorkers at once, so I'm assuming I running into the same barrier.

When the script runs more than once, the WebWorkers that were instantiated in the first round no longer need to exist; I don't reuse any WebWorker objects. I would like to destroy the WebWorkers that were created the first time through so that future executions of the script don't stall while attempting to spawn new WebWorkers.

I've only noticed this problem in Chrome and Firefox; Safari doesn't seem to have this limitation.

like image 626
Nathan Friend Avatar asked Feb 23 '13 00:02

Nathan Friend


1 Answers

You should be able to call this from the main window to immediately terminate a worker:

myWorker.terminate();

See the full API here: https://developer.mozilla.org/en-US/docs/DOM/Using_web_workers

Alternatively, you can call close() from the worker itself see: https://developer.mozilla.org/en-US/docs/DOM/Using_web_workers

like image 191
Andrew Eisenberg Avatar answered Oct 23 '22 07:10

Andrew Eisenberg