UNPKG

419 BMarkdownView Raw
1## Loading the worker code from a file (worker side)
2
3This file contains the pong (worker) side of our ping pong example.
4It is loaded by a `t.load` call in `ex4_main.js`.
5
6``` javascript
7function fibo(n) {
8 return n > 1 ? fibo(n - 1) + fibo(n - 2) : 1;
9}
10
11// returning the next fibonacci number when a 'next' event comes in:
12var i = 1;
13thread.on('next', function() {
14 thread.emit('data', i, fibo(i));
15 i++;
16});
17```
18