Created
September 19, 2010 19:34
-
-
Save mrfabbri/587050 to your computer and use it in GitHub Desktop.
A quick scaffolding html file to load a web worker at runtime, a sample web worker file is provided. Aimed at tinkering with project euler problems in JavaScript without freezing the browser.
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
<html> | |
<head> | |
<title> | |
</title> | |
<style> | |
#input-area{ | |
width: 400px; | |
margin: 10px; | |
} | |
#output-area{ | |
width: 400px; | |
height: 100px; | |
margin: 10px; | |
} | |
</style> | |
<script> | |
var evalWorker; | |
function initEvalWorker(workerJSFile) | |
{ | |
evalWorker = new Worker(workerJSFile); | |
evalWorker.addEventListener('message', function(event) | |
{ | |
document.getElementById("output-area").textContent = event.data; | |
}, false); | |
} | |
function stop() | |
{ | |
evalWorker.terminate(); | |
} | |
function rep() | |
{ | |
initEvalWorker(document.getElementById("input-area").value); | |
evalWorker.postMessage("START"); | |
} | |
</script> | |
</head> | |
<body> | |
<div> | |
worker JavaScript file: | |
<input type="text" id="input-area"></textarea> | |
</div> | |
<div> | |
<button type="button" onclick="rep();">SOLVE</button> | |
<button type="button" onclick="stop();">STOP</button> | |
</div> | |
<div id="output-area"> | |
</div> | |
</body> | |
</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
onmessage = function (event) | |
{ | |
var result; | |
result = 42; | |
postMessage(result); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment