summaryrefslogtreecommitdiff
path: root/node_modules/webworker-threads/examples/quickIntro_multiThread.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/webworker-threads/examples/quickIntro_multiThread.js')
-rw-r--r--node_modules/webworker-threads/examples/quickIntro_multiThread.js16
1 files changed, 16 insertions, 0 deletions
diff --git a/node_modules/webworker-threads/examples/quickIntro_multiThread.js b/node_modules/webworker-threads/examples/quickIntro_multiThread.js
new file mode 100644
index 0000000..86e861e
--- /dev/null
+++ b/node_modules/webworker-threads/examples/quickIntro_multiThread.js
@@ -0,0 +1,16 @@
+function fibo (n) {
+ return n > 1 ? fibo(n - 1) + fibo(n - 2) : 1;
+}
+
+var numThreads= 10;
+var threadPool= require('webworker-threads').createPool(numThreads).all.eval(fibo);
+
+threadPool.all.eval('fibo(35)', function cb (err, data) {
+ process.stdout.write(" ["+ this.id+ "]"+ data);
+ this.eval('fibo(35)', cb);
+});
+
+(function spinForever () {
+ process.stdout.write(".");
+ process.nextTick(spinForever);
+})();