blob: fed6f41622c2cce350b5f3592bacb18ca584e0c5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
var Worker = require('webworker-threads').Worker;
var w = new Worker(function(){
function fibo (n) {
return n > 1 ? fibo(n - 1) + fibo(n - 2) : 1;
}
self.onmessage = function (event) {
self.postMessage( fibo( event.data ) );
};
});
w.postMessage(Math.ceil(Math.random()*30));
w.onmessage = function cb (event) {
process.stdout.write(event.data);
w.postMessage(Math.ceil(Math.random()*30));
};
(function spinForever () {
process.stdout.write(".");
process.nextTick(spinForever);
})();
|