summaryrefslogtreecommitdiff
path: root/node_modules/webworker-threads/examples/ex04_worker.md
diff options
context:
space:
mode:
authoryo mama <pepper@scannerjammer.com>2015-04-04 01:00:59 -0700
committeryo mama <pepper@scannerjammer.com>2015-04-04 01:00:59 -0700
commitc7c22e3db1c826bcfb2bc66651ec480aae0d4ae0 (patch)
tree8546df448afef40d3814d2581f4dacff7cebb87f /node_modules/webworker-threads/examples/ex04_worker.md
Diffstat (limited to 'node_modules/webworker-threads/examples/ex04_worker.md')
-rw-r--r--node_modules/webworker-threads/examples/ex04_worker.md18
1 files changed, 18 insertions, 0 deletions
diff --git a/node_modules/webworker-threads/examples/ex04_worker.md b/node_modules/webworker-threads/examples/ex04_worker.md
new file mode 100644
index 0000000..1304675
--- /dev/null
+++ b/node_modules/webworker-threads/examples/ex04_worker.md
@@ -0,0 +1,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++;
+});
+```
+