Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Unstoppable Web Worker
<p>Start the worker from the browser console (fire up a CPU monitor to
have some sort of visual feedback)</p>
<p>you will NOT be able to stop it with</p>
<p>What I'd expected:</p>
<pre>worker.postMessage("run") // start
worker.postMessage("stop") // stop
worker.postMessage("run") // start from where it was interrupted</pre>
<script type="text/javascript">
var worker = new Worker("worker.js");
var count = 0,
running = false,
iface = {}; = function ()
running = true;
while (running) {
iface.stop = function ()
running = false;
onmessage = function (ev)
var func_name =;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment