Skip to content

Instantly share code, notes, and snippets.

@devdays
Created November 30, 2014 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devdays/140480975c7b2043c038 to your computer and use it in GitHub Desktop.
Save devdays/140480975c7b2043c038 to your computer and use it in GitHub Desktop.
Web Worker Calculates Pi HTML
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Calculate Pi</title>
</head>
<body>
<p>The longest pi so far is: <output id="result"></output></p>
<p>pi = 3.14159265</p>
<button onclick="stopWorker()">Stop Worker</button>
<script>
var work;
if (typeof (Worker) !== "undefined") {
if (typeof (work) == "undefined") {
work = new Worker('2-CalculatePi.js');
work.addEventListener('message', function (e) {
document.getElementById('result').textContent = e.data;
}, false);
work.addEventListener('error', function (e) {
document.getElementById('result').textContent = e.message;
},
false);
}
}
else {
document.getElementById('result').textContent = " not supported.";
}
function stopWorker() {
work.terminate();
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment