Permalink
Browse files

added demos for thread-pools.

  • Loading branch information...
1 parent 3da4b36 commit 3bab4b455ac2a1c15dc934d6b435a18446cbc2d1 Joachim Kainz committed Oct 3, 2011
Showing with 34 additions and 0 deletions.
  1. +16 −0 examples/multi-master.js
  2. +18 −0 examples/multi-worker.js
View
@@ -0,0 +1,16 @@
+var backgrounder = require("../lib/backgrounder");
+var worker = backgrounder.spawn(__dirname + "/multi-worker.js", {
+ "children-count" : 5
+});
+
+var counter = 0;
+
+for(var idx=0; idx<10; idx++) {
+ worker.send({}, function(arg1, arg2, arg3) {
+ console.log("Master: client called the callback with %s arguments:",
+ arguments.length, arg1, arg2, arg3);
+ if (++counter === 10) {
+ worker.terminate();
+ }
+ });
+}
View
@@ -0,0 +1,18 @@
+var http = require('http');
+var id = Math.random()*10000000000000000;
+
+process.on('message', function(message, callback) {
+ var options = {
+ host: 'www.google.com',
+ port: 80,
+ path: '/index.html'
+ };
+
+ http.get(options, function(res) {
+ callback(id, "status-code:", res.statusCode);
+ }).on('error', function(e) {
+ callback("error:", e);
+ });
+});
+
+console.log('Worker: Started %s!', id);

0 comments on commit 3bab4b4

Please sign in to comment.