<p>Is there some way to do multi-threading in JavaScript?</p>

[{'answer_id': 30043, 'author': 'jsight', 'author_id': 1432, 'author_profile': 'https://Stackoverflow.com/users/1432', 'pm_score': 2, 'selected': False, 'text': '<p>In raw Javascript, the best that you can do is using the few asynchronous calls (xmlhttprequest), but that\'s not really threading and very limited.  <a href="http://gears.google.com/" rel="nofollow noreferrer">Google Gears</a> adds a number of APIs to the browser, some of which can be used for threading support.</p>\n'}, {'answer_id': 30050, 'author': 'Svend', 'author_id': 2491, 'author_profile': 'https://Stackoverflow.com/users/2491', 'pm_score': 4, 'selected': False, 'text': '<p>There\'s no true threading in JavaScript. JavaScript being the malleable language that it is, does allow you to emulate some of it. Here is an <a href="http://www.neilmix.com/2007/02/07/threading-in-javascript-17/" rel="noreferrer">example</a> I came across the other day.</p>\n'}, {'answer_id': 30197, 'author': 'Sam Hasler', 'author_id': 2541, 'author_profile': 'https://Stackoverflow.com/users/2541', 'pm_score': 8, 'selected': True, 'text': '<p>See <a href="http://caniuse.com/#search=worker" rel="nofollow noreferrer">http://caniuse.com/#search=worker</a> for the most up-to-date support info.</p>\n<p>The following was the state of support circa 2009.</p>\n<hr />\n<p>The words you want to google for are <a href="http://www.google.com/search?q=JavaScript+worker+threads" rel="nofollow noreferrer">JavaScript Worker Threads</a></p>\n<p>Apart from from <a href="http://gears.google.com/" rel="nofollow noreferrer">Gears</a> there\'s nothing available right now, but there\'s plenty of talk about how to implement this so I guess watch this question as the answer will no doubt change in future.</p>\n<p>Here\'s the relevant documentation for Gears: <a href="http://code.google.com/apis/gears/api_workerpool.html" rel="nofollow noreferrer">WorkerPool API</a></p>\n<p>WHATWG has a Draft Recommendation for worker threads: <a href="http://www.whatwg.org/specs/web-workers/current-work/" rel="nofollow noreferrer">Web Workers</a></p>\n<p>And there\'s also Mozilla’s <a href="https://wiki.mozilla.org/DOMWorkerThreads" rel="nofollow noreferrer">DOM Worker Threads</a></p>\n<hr />\n<p><strong>Update:</strong> June 2009, current state of browser support for JavaScript threads</p>\n<p><strong>Firefox 3.5</strong> has web workers. Some demos of web workers, if you want to see them in action:</p>\n<ul>\n<li><a href="http://blog.mozbox.org/post/2009/04/10/Web-Workers-in-action" rel="nofollow noreferrer">Simulated Annealing</a> (&quot;Try it&quot; link)</li>\n<li><a href="https://web.archive.org/web/20120406122342/https://developer.mozilla.org/web-tech/2008/12/04/web-workers-part-2" rel="nofollow noreferrer">Space Invaders</a> (link at end of post)</li>\n<li><a href="http://www.yafla.com/dforbes/Web_Workers_and_You__A_Faster_More_Powerful_JavaScript_World" rel="nofollow noreferrer">MoonBat JavaScript Benchmark</a> (first link)</li>\n</ul>\n<p>The Gears plugin can also be installed in Firefox.</p>\n<p><strong>Safari 4</strong>, and the <strong>WebKit nightlies</strong> have worker threads:</p>\n<ul>\n<li><a href="http://blog.owensperformance.com/2009/02/safari-4-worker-threads-javascript-domination/" rel="nofollow noreferrer">JavaScript Ray Tracer</a></li>\n</ul>\n<p><strong>Chrome</strong> has Gears baked in, so it can do threads, although it requires a confirmation prompt from the user (and it uses a different API to web workers, although it will work in any browser with the Gears plugin installed):</p>\n<ul>\n<li><a href="http://code.google.com/apis/gears/samples/hello_world_workerpool/hello_world_workerpool.html" rel="nofollow noreferrer">Google Gears WorkerPool Demo</a> (not a good example as it runs too fast to test in Chrome and Firefox, although IE runs it slow enough to see it blocking interaction)</li>\n</ul>\n<p><strong>IE8</strong> and <strong>IE9</strong> can only do threads with the Gears plugin installed</p>\n'}, {'answer_id': 30200, 'author': '17 of 26', 'author_id': 2284, 'author_profile': 'https://Stackoverflow.com/users/2284', 'pm_score': 4, 'selected': False, 'text': '<p>There is no true multi-threading in Javascript, but you can get asynchronous behavior using <code>setTimeout()</code> and asynchronous AJAX requests.</p>\n\n<p>What exactly are you trying to accomplish?</p>\n'}, {'answer_id': 30845, 'author': 'Antoine Aubry', 'author_id': 2680, 'author_profile': 'https://Stackoverflow.com/users/2680', 'pm_score': 3, 'selected': False, 'text': '<p>You could use <a href="http://www.neilmix.com/narrativejs/doc/" rel="noreferrer">Narrative JavaScript</a>, a compiler that will transforms your code into a state machine, effectively allowing you to emulate threading. It does so by adding a "yielding" operator (notated as \'->\') to the language that allows you to write asynchronous code in a single, linear code block.</p>\n'}, {'answer_id': 40041, 'author': 'juan', 'author_id': 1782, 'author_profile': 'https://Stackoverflow.com/users/1782', 'pm_score': 2, 'selected': False, 'text': '<p>The new v8 engine which <a href="http://googleblog.blogspot.com/2008/09/fresh-take-on-browser.html" rel="nofollow noreferrer">should come out</a> today supports it (i think)</p>\n'}, {'answer_id': 7179493, 'author': 'djondal', 'author_id': 388465, 'author_profile': 'https://Stackoverflow.com/users/388465', 'pm_score': 4, 'selected': False, 'text': '<p>With the HTML5 "side-specs" <em>no need to hack javascript anymore</em> with  setTimeout(), setInterval(), etc.</p>\n\n<p>HTML5 &amp; Friends introduces the javascript <strong>Web Workers</strong> specification. It is an API for running scripts asynchronously and independently.</p>\n\n<p>Links to the <a href="https://html.spec.whatwg.org/multipage/workers.html" rel="nofollow noreferrer">specification</a> and a <a href="http://www.html5rocks.com/en/tutorials/workers/basics/" rel="nofollow noreferrer">tutorial</a>.</p>\n'}, {'answer_id': 13710318, 'author': 'Jono', 'author_id': 1876818, 'author_profile': 'https://Stackoverflow.com/users/1876818', 'pm_score': 2, 'selected': False, 'text': "<p>If you can't or don't want to use any AJAX stuff, use an iframe or ten! ;) You can have processes running in iframes in parallel with the master page without worrying about cross browser comparable issues or syntax issues with dot net AJAX etc, and you can call the master page's JavaScript (including the JavaScript that it has imported) from an iframe. </p>\n\n<p>E.g, in a parent iframe, to call <code>egFunction()</code> in the parent document once the iframe content has loaded (that's the asynchronous part)</p>\n\n<pre><code>parent.egFunction();\n</code></pre>\n\n<p>Dynamically generate the iframes too so the main html code is free from them if you want.</p>\n"}, {'answer_id': 21649532, 'author': 'Ahmet Can Güven', 'author_id': 836048, 'author_profile': 'https://Stackoverflow.com/users/836048', 'pm_score': 3, 'selected': False, 'text': '<p>Here is just a way to <strong>simulate</strong> multi-threading in Javascript</p>\n\n<p>Now I am going to create 3 threads which will calculate numbers addition, numbers can be divided with 13 and numbers can be divided with 3 till 10000000000. And these 3 functions are not able to run in same time as what Concurrency means. But I will show you a trick that will make these functions run recursively in the same time : <a href="http://jsfiddle.net/F6Rg8/10/" rel="noreferrer">jsFiddle</a></p>\n\n<p>This code belongs to me.</p>\n\n<p>Body Part</p>\n\n<pre><code>    &lt;div class="div1"&gt;\n    &lt;input type="button" value="start/stop" onclick="_thread1.control ? _thread1.stop() : _thread1.start();" /&gt;&lt;span&gt;Counting summation of numbers till 10000000000&lt;/span&gt; = &lt;span id="1"&gt;0&lt;/span&gt;\n&lt;/div&gt;\n&lt;div class="div2"&gt;\n    &lt;input type="button" value="start/stop" onclick="_thread2.control ? _thread2.stop() : _thread2.start();" /&gt;&lt;span&gt;Counting numbers can be divided with 13 till 10000000000&lt;/span&gt; = &lt;span id="2"&gt;0&lt;/span&gt;\n&lt;/div&gt;\n&lt;div class="div3"&gt;\n    &lt;input type="button" value="start/stop" onclick="_thread3.control ? _thread3.stop() : _thread3.start();" /&gt;&lt;span&gt;Counting numbers can be divided with 3 till 10000000000&lt;/span&gt; = &lt;span id="3"&gt;0&lt;/span&gt;\n&lt;/div&gt;\n</code></pre>\n\n<p>Javascript Part</p>\n\n<pre><code>var _thread1 = {//This is my thread as object\n    control: false,//this is my control that will be used for start stop\n    value: 0, //stores my result\n    current: 0, //stores current number\n    func: function () {   //this is my func that will run\n        if (this.control) {      // checking for control to run\n            if (this.current &lt; 10000000000) {\n                this.value += this.current;   \n                document.getElementById("1").innerHTML = this.value;\n                this.current++;\n            }\n        }\n        setTimeout(function () {  // And here is the trick! setTimeout is a king that will help us simulate threading in javascript\n            _thread1.func();    //You cannot use this.func() just try to call with your object name\n        }, 0);\n    },\n    start: function () {\n        this.control = true;   //start function\n    },\n    stop: function () {\n        this.control = false;    //stop function\n    },\n    init: function () {\n        setTimeout(function () {\n            _thread1.func();    // the first call of our thread\n        }, 0)\n    }\n};\nvar _thread2 = {\n    control: false,\n    value: 0,\n    current: 0,\n    func: function () {\n        if (this.control) {\n            if (this.current % 13 == 0) {\n                this.value++;\n            }\n            this.current++;\n            document.getElementById("2").innerHTML = this.value;\n        }\n        setTimeout(function () {\n            _thread2.func();\n        }, 0);\n    },\n    start: function () {\n        this.control = true;\n    },\n    stop: function () {\n        this.control = false;\n    },\n    init: function () {\n        setTimeout(function () {\n            _thread2.func();\n        }, 0)\n    }\n};\nvar _thread3 = {\n    control: false,\n    value: 0,\n    current: 0,\n    func: function () {\n        if (this.control) {\n            if (this.current % 3 == 0) {\n                this.value++;\n            }\n            this.current++;\n            document.getElementById("3").innerHTML = this.value;\n        }\n        setTimeout(function () {\n            _thread3.func();\n        }, 0);\n    },\n    start: function () {\n        this.control = true;\n    },\n    stop: function () {\n        this.control = false;\n    },\n    init: function () {\n        setTimeout(function () {\n            _thread3.func();\n        }, 0)\n    }\n};\n\n_thread1.init();\n_thread2.init();\n_thread3.init();\n</code></pre>\n\n<p>I hope this way will be helpful.</p>\n'}, {'answer_id': 27926880, 'author': 'Amitay Dobo', 'author_id': 282352, 'author_profile': 'https://Stackoverflow.com/users/282352', 'pm_score': 2, 'selected': False, 'text': '<p>Another possible method is using an javascript interpreter in the javascript environment. </p>\n\n<p>By creating multiple interpreters and controlling their execution from the main thread, you can simulate multi-threading with each thread running in its own environment.</p>\n\n<p>The approach is somewhat similar to web workers, but you give the interpreter access to the browser global environment.</p>\n\n<p>I made a small project to <a href="http://www.doboism.com/projects/JS-Interpreter/asyncDemo/asyncDemo.html" rel="nofollow">demonstrate this</a>.</p>\n\n<p>A more detailed explanation in <a href="http://www.doboism.com/blog/2015/01/13/multi-threaded-javascript-using-an-interpreter/" rel="nofollow">this blog post</a>.</p>\n'}, {'answer_id': 30891727, 'author': 'Ludovic Feltz', 'author_id': 2576706, 'author_profile': 'https://Stackoverflow.com/users/2576706', 'pm_score': 6, 'selected': False, 'text': '<h1>Different way to do multi-threading and Asynchronous in JavaScript</h1>\n\n<p>Before HTML5 JavaScript only allowed the execution of one thread per page.  </p>\n\n<p>There was some hacky way to simulate an asynchronous execution with <em>Yield</em>, <code>setTimeout()</code>, <code>setInterval()</code>, <code>XMLHttpRequest</code> or <em>event handlers</em> (see the end of this post for an example with <em>yield</em> and <code>setTimeout()</code>).</p>\n\n<p>But with HTML5 we can now use Worker Threads to parallelize the execution of functions. Here is an example of use.</p>\n\n<hr>\n\n<h1>Real multi-threading</h1>\n\n<h2>Multi-threading: JavaScript Worker Threads</h2>\n\n<p><em>HTML5</em> introduced Web Worker Threads (see: <a href="http://caniuse.com/#search=worker" rel="noreferrer">browsers compatibilities</a>)<br>\nNote: IE9 and earlier versions do not support it.</p>\n\n<p>These worker threads are JavaScript threads that run in background without affecting the performance of the page. For more information about <strong>Web Worker</strong> <a href="http://www.w3.org/TR/2009/WD-workers-20091029/" rel="noreferrer">read the documentation</a> or <a href="http://www.html5rocks.com/en/tutorials/workers/basics/" rel="noreferrer">this tutorial</a>.</p>\n\n<p>Here is a simple example with 3 Web Worker threads that count to MAX_VALUE and show the current computed value in our page:</p>\n\n<p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">\r\n<div class="snippet-code">\r\n<pre class="snippet-code-js lang-js prettyprint-override"><code>//As a worker normally take another JavaScript file to execute we convert the function in an URL: http://stackoverflow.com/a/16799132/2576706\r\nfunction getScriptPath(foo){ return window.URL.createObjectURL(new Blob([foo.toString().match(/^\\s*function\\s*\\(\\s*\\)\\s*\\{(([\\s\\S](?!\\}$))*[\\s\\S])/)[1]],{type:\'text/javascript\'})); }\r\n\r\nvar MAX_VALUE = 10000;\r\n\r\n/*\r\n * Here are the workers\r\n */\r\n//Worker 1\r\nvar worker1 = new Worker(getScriptPath(function(){\r\n    self.addEventListener(\'message\', function(e) {\r\n        var value = 0;\r\n        while(value &lt;= e.data){\r\n            self.postMessage(value);\r\n            value++;\r\n        }\r\n    }, false);\r\n}));\r\n//We add a listener to the worker to get the response and show it in the page\r\nworker1.addEventListener(\'message\', function(e) {\r\n  document.getElementById("result1").innerHTML = e.data;\r\n}, false);\r\n\r\n\r\n//Worker 2\r\nvar worker2 = new Worker(getScriptPath(function(){\r\n    self.addEventListener(\'message\', function(e) {\r\n        var value = 0;\r\n        while(value &lt;= e.data){\r\n            self.postMessage(value);\r\n            value++;\r\n        }\r\n    }, false);\r\n}));\r\nworker2.addEventListener(\'message\', function(e) {\r\n  document.getElementById("result2").innerHTML = e.data;\r\n}, false);\r\n\r\n\r\n//Worker 3\r\nvar worker3 = new Worker(getScriptPath(function(){\r\n    self.addEventListener(\'message\', function(e) {\r\n        var value = 0;\r\n        while(value &lt;= e.data){\r\n            self.postMessage(value);\r\n            value++;\r\n        }\r\n    }, false);\r\n}));\r\nworker3.addEventListener(\'message\', function(e) {\r\n    document.getElementById("result3").innerHTML = e.data;\r\n}, false);\r\n\r\n\r\n// Start and send data to our worker.\r\nworker1.postMessage(MAX_VALUE); \r\nworker2.postMessage(MAX_VALUE); \r\nworker3.postMessage(MAX_VALUE);</code></pre>\r\n<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="result1"&gt;&lt;/div&gt;\r\n&lt;div id="result2"&gt;&lt;/div&gt;\r\n&lt;div id="result3"&gt;&lt;/div&gt;</code></pre>\r\n</div>\r\n</div>\r\n</p>\n\n<p>We can see that the three threads are executed in concurrency and print their current value in the page. They don\'t freeze the page because they are executed in the background with separated threads.</p>\n\n<hr>\n\n<h2>Multi-threading: with multiple iframes</h2>\n\n<p>Another way to achieve this is to use multiple <em>iframes</em>, each one will execute a thread. We can give the <em>iframe</em> some parameters by the URL and the <em>iframe</em> can communicate with his parent in order to get the result and print it back (the <em>iframe</em> must be in the same domain).</p>\n\n<p><strong>This example doesn\'t work in all browsers!</strong> <em>iframes</em> usually run in the same thread/process as the main page (but Firefox and Chromium seem to handle it differently).</p>\n\n<p>Since the code snippet does not support multiple HTML files, I will just provide the different codes here:</p>\n\n<p><strong>index.html:</strong></p>\n\n<pre><code>//The 3 iframes containing the code (take the thread id in param)\n&lt;iframe id="threadFrame1" src="thread.html?id=1"&gt;&lt;/iframe&gt;\n&lt;iframe id="threadFrame2" src="thread.html?id=2"&gt;&lt;/iframe&gt;\n&lt;iframe id="threadFrame3" src="thread.html?id=3"&gt;&lt;/iframe&gt;\n\n//Divs that shows the result\n&lt;div id="result1"&gt;&lt;/div&gt;\n&lt;div id="result2"&gt;&lt;/div&gt;\n&lt;div id="result3"&gt;&lt;/div&gt;\n\n\n&lt;script&gt;\n    //This function is called by each iframe\n    function threadResult(threadId, result) {\n        document.getElementById("result" + threadId).innerHTML = result;\n    }\n&lt;/script&gt;\n</code></pre>\n\n<p><strong>thread.html:</strong></p>\n\n<pre><code>//Get the parameters in the URL: http://stackoverflow.com/a/1099670/2576706\nfunction getQueryParams(paramName) {\n    var qs = document.location.search.split(\'+\').join(\' \');\n    var params = {}, tokens, re = /[?&amp;]?([^=]+)=([^&amp;]*)/g;\n    while (tokens = re.exec(qs)) {\n        params[decodeURIComponent(tokens[1])] = decodeURIComponent(tokens[2]);\n    }\n    return params[paramName];\n}\n\n//The thread code (get the id from the URL, we can pass other parameters as needed)\nvar MAX_VALUE = 100000;\n(function thread() {\n    var threadId = getQueryParams(\'id\');\n    for(var i=0; i&lt;MAX_VALUE; i++){\n        parent.threadResult(threadId, i);\n    }\n})();\n</code></pre>\n\n<hr>\n\n<h1>Simulate multi-threading</h1>\n\n<h2>Single-thread: emulate JavaScript concurrency with setTimeout()</h2>\n\n<p>The \'naive\' way would be to execute the function <code>setTimeout()</code> one after the other like this:</p>\n\n<pre><code>setTimeout(function(){ /* Some tasks */ }, 0);\nsetTimeout(function(){ /* Some tasks */ }, 0);\n[...]\n</code></pre>\n\n<p>But this method <strong>does not work</strong> because each task will be executed one after the other.  </p>\n\n<p>We can simulate asynchronous execution by calling the function recursively like this:</p>\n\n<p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">\r\n<div class="snippet-code">\r\n<pre class="snippet-code-js lang-js prettyprint-override"><code>var MAX_VALUE = 10000;\r\n\r\nfunction thread1(value, maxValue){\r\n    var me = this;\r\n    document.getElementById("result1").innerHTML = value;\r\n    value++;\r\n  \r\n    //Continue execution\r\n    if(value&lt;=maxValue)\r\n        setTimeout(function () { me.thread1(value, maxValue); }, 0);\r\n}\r\n\r\nfunction thread2(value, maxValue){\r\n    var me = this;\r\n    document.getElementById("result2").innerHTML = value;\r\n    value++;\r\n \r\n    if(value&lt;=maxValue)\r\n        setTimeout(function () { me.thread2(value, maxValue); }, 0);\r\n}\r\n\r\nfunction thread3(value, maxValue){\r\n    var me = this;\r\n    document.getElementById("result3").innerHTML = value;\r\n    value++;\r\n \r\n    if(value&lt;=maxValue)\r\n        setTimeout(function () { me.thread3(value, maxValue); }, 0);\r\n}\r\n\r\nthread1(0, MAX_VALUE);\r\nthread2(0, MAX_VALUE);\r\nthread3(0, MAX_VALUE);</code></pre>\r\n<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="result1"&gt;&lt;/div&gt;\r\n&lt;div id="result2"&gt;&lt;/div&gt;\r\n&lt;div id="result3"&gt;&lt;/div&gt;</code></pre>\r\n</div>\r\n</div>\r\n</p>\n\n<p>As you can see this second method is very slow and freezes the browser because it uses the main thread to execute the functions.</p>\n\n<hr>\n\n<h2>Single-thread: emulate JavaScript concurrency with yield</h2>\n\n<p><em><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/yield" rel="noreferrer">Yield</a></em> is a new feature in <strong>ECMAScript 6</strong>, it only works on the oldest version of Firefox and Chrome (in Chrome you need to enable <strong>Experimental JavaScript</strong> appearing in <em>chrome://flags/#enable-javascript-harmony</em>).</p>\n\n<blockquote>\n  <p>The yield keyword causes generator function execution to pause and the value of the expression following the yield keyword is returned to the generator\'s caller. It can be thought of as a generator-based version of the return keyword.</p>\n</blockquote>\n\n<p>A generator allows you to suspend execution of a function and resume it later. A generator can be used to schedule your functions with a technique called <a href="http://www.neilmix.com/2007/02/07/threading-in-javascript-17/" rel="noreferrer">trampolining</a>.</p>\n\n<p>Here is the example:</p>\n\n<p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">\r\n<div class="snippet-code">\r\n<pre class="snippet-code-js lang-js prettyprint-override"><code>var MAX_VALUE = 10000;\r\n\r\nScheduler = {\r\n _tasks: [],\r\n add: function(func){\r\n  this._tasks.push(func);\r\n }, \r\n start: function(){\r\n  var tasks = this._tasks;\r\n  var length = tasks.length;\r\n  while(length&gt;0){\r\n   for(var i=0; i&lt;length; i++){\r\n    var res = tasks[i].next();\r\n    if(res.done){\r\n     tasks.splice(i, 1);\r\n     length--;\r\n     i--;\r\n    }\r\n   }\r\n  }\r\n } \r\n}\r\n\r\n\r\nfunction* updateUI(threadID, maxValue) {\r\n  var value = 0;\r\n  while(value&lt;=maxValue){\r\n yield document.getElementById("result" + threadID).innerHTML = value;\r\n value++;\r\n  }\r\n}\r\n\r\nScheduler.add(updateUI(1, MAX_VALUE));\r\nScheduler.add(updateUI(2, MAX_VALUE));\r\nScheduler.add(updateUI(3, MAX_VALUE));\r\n\r\nScheduler.start()</code></pre>\r\n<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="result1"&gt;&lt;/div&gt;\r\n&lt;div id="result2"&gt;&lt;/div&gt;\r\n&lt;div id="result3"&gt;&lt;/div&gt;</code></pre>\r\n</div>\r\n</div>\r\n</p>\n'}, {'answer_id': 40326763, 'author': 'Chad Scira', 'author_id': 103696, 'author_profile': 'https://Stackoverflow.com/users/103696', 'pm_score': 1, 'selected': False, 'text': '<p>Javascript doesn\'t have threads, but we do have workers.</p>\n\n<p>Workers may be a good choice if you don\'t need shared objects.</p>\n\n<p>Most browser implementations will actually spread workers across all cores allowing you to utilize all cores. You can see a demo of this <a href="http://s.codepen.io/icodeforlove/debug/ZOjBBB" rel="nofollow">here</a>.</p>\n\n<p>I have developed a library called <strong>task.js</strong> that makes this very easy to do.</p>\n\n<blockquote>\n  <p><strong><a href="https://github.com/icodeforlove/task.js" rel="nofollow">task.js</a></strong> Simplified interface for getting CPU intensive code to run on all cores (node.js, and web)</p>\n</blockquote>\n\n<p>A example would be</p>\n\n<pre><code>function blocking (exampleArgument) {\n    // block thread\n}\n\n// turn blocking pure function into a worker task\nconst blockingAsync = task.wrap(blocking);\n\n// run task on a autoscaling worker pool\nblockingAsync(\'exampleArgumentValue\').then(result =&gt; {\n    // do something with result\n});\n</code></pre>\n'}, {'answer_id': 40624783, 'author': 'Mandeep Singh', 'author_id': 5009757, 'author_profile': 'https://Stackoverflow.com/users/5009757', 'pm_score': 0, 'selected': False, 'text': '<p>With HTML5 <a href="https://www.w3.org/TR/workers/" rel="nofollow noreferrer">specification</a> you do not need to write too much JS for the same or find some hacks.</p>\n\n<p>One of the feature introduced in HTML5 is <a href="http://www.w3schools.com/html/html5_webworkers.asp" rel="nofollow noreferrer">Web Workers</a> which is JavaScript running in the background,independently of other scripts, without affecting the performance of the page. </p>\n\n<p>It is supported in almost all browsers : </p>\n\n<p>Chrome  -  4.0+ </p>\n\n<p>IE      -  10.0+</p>\n\n<p>Mozilla -  3.5+</p>\n\n<p>Safari  -  4.0+</p>\n\n<p>Opera   -  11.5+</p>\n'}, {'answer_id': 69761871, 'author': 'Ahmed Yasin Koculu', 'author_id': 673692, 'author_profile': 'https://Stackoverflow.com/users/673692', 'pm_score': 0, 'selected': False, 'text': '<p>Topaz is lock free Multithreaded Javascript Engine for .NET: <a href="https://github.com/koculu/topaz" rel="nofollow noreferrer">https://github.com/koculu/topaz</a></p>\n'}]
['https://Stackoverflow.com/questions/30036', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/184/']