Created
July 10, 2009 05:41
-
-
Save abhiyerra/144259 to your computer and use it in GitHub Desktop.
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
/* fib.js */ | |
i = 2; | |
while(true) { | |
postMessage(i + " " + fib(i)); | |
i++; | |
} | |
function fib(n){ | |
return n < 2 ? n : fib(n-1) +fib(n-2); | |
} |
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> | |
<head> | |
<meta http-equiv="content-type" content="text/html; charset=utf-8"> | |
<title>Index</title> | |
<script type="text/javascript" charset="utf-8"> | |
fib = new Worker('fib.js'); | |
sayhello = new Worker('sayhello.js'); | |
fib.onmessage = function(event) { | |
document.getElementById("fib").innerHTML = event.data; | |
} | |
sayhello.onmessage = function(event) { | |
document.getElementById("sayHello").innerHTML = event.data; | |
} | |
function callSayHello(f) { | |
document.getElementById("sayHelloNoThread").innerHTML = "NoThread:" + f.value; | |
sayhello.postMessage(f.value); | |
} | |
</script> | |
</head> | |
<body> | |
<h1>Fib</h1> | |
<span id="fib"></span> | |
<h1>Say Hello</h1> | |
<input type="text" onkeyup="callSayHello(this);" /><br/> | |
<span id="sayHello"></span><br/> | |
<span id="sayHelloNoThread"></span> | |
</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
/* sayhello.js */ | |
function sayHello(v) { | |
return "Hello there from thread " + v; | |
} | |
onmessage = function(event) { | |
postMessage(sayHello(event.data)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment