1 | ## Loading the worker code from a file (worker side)
|
2 |
|
3 | This file contains the pong (worker) side of our ping pong example.
|
4 | It is loaded by a `t.load` call in `ex4_main.js`.
|
5 |
|
6 | ``` javascript
|
7 | function 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:
|
12 | var i = 1;
|
13 | thread.on('next', function() {
|
14 | thread.emit('data', i, fibo(i));
|
15 | i++;
|
16 | });
|
17 | ```
|
18 |
|