Created
November 30, 2014 21:27
-
-
Save devdays/140480975c7b2043c038 to your computer and use it in GitHub Desktop.
Web Worker Calculates Pi HTML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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