Last active
October 7, 2020 10:17
-
-
Save sverhoeven/00d0ae0ad401d65229c12f36592e3c2f to your computer and use it in GitHub Desktop.
run-cpp-on-web: web-worker
This file contains hidden or 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 lang="en"> | |
<head> | |
<title>Web worker example</title> | |
<script> | |
const worker = new Worker('worker.js'); | |
worker.postMessage({ | |
type: 'CALCULATE', | |
payload: { tolerance: 0.001, initial_guess: -4.0 } | |
}); | |
worker.onmessage = function(message) { | |
if (message.data.type === 'RESULT') { | |
const root = message.data.payload.root; | |
document.getElementById('answer').innerHTML = | |
"Function root is approximately at x = " + root.toFixed(2); | |
} | |
} | |
</script> | |
</head> | |
<body> | |
<div class="slidecontainer"> | |
<input type="range" min="1" max="100" value="50" class="slider" id="myRange"> | |
</div> | |
<span id="answer"> If you can see this text, WebAssembly code is still running... </span> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment