summaryrefslogtreecommitdiff
path: root/node_modules/webworker-threads/examples/ex04_worker.md
blob: 13046750d57cd3af373d3b8b1086f8c100e959d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
## Loading the worker code from a file (worker side)

This file contains the pong (worker) side of our ping pong example.  
It is loaded by a `t.load` call in `ex4_main.js`.

``` javascript
function fibo(n) {
	return n > 1 ? fibo(n - 1) + fibo(n - 2) : 1;
}

// returning the next fibonacci number when a 'next' event comes in:
var i = 1;
thread.on('next', function() {
	thread.emit('data', i, fibo(i));
	i++;
});
```