Permalink
Browse files

now support legacy & callback interface.

  • Loading branch information...
1 parent aeb914e commit acbd9e3844841d4ea8c2123c2619385e10da8184 Joachim Kainz committed Oct 2, 2011
Showing with 19 additions and 19 deletions.
  1. +7 −9 examples/simple-master.js
  2. +12 −10 lib/backgrounder.js
View
16 examples/simple-master.js
@@ -1,11 +1,9 @@
var backgrounder = require("../lib/backgrounder");
-
-backgrounder.spawn(__dirname + "/simple-worker.js", function(worker){
- worker.send({
- "company": "jolira"
- }, function(arg1, arg2, arg3) {
- console.log("Master: client called the callback with %s arguments:",
- arguments.length, arg1, arg2, arg3);
- worker.terminate();
- });
+var worker = backgrounder.spawn(__dirname + "/simple-worker.js");
+worker.send({
+ "company": "jolira"
+}, function(arg1, arg2, arg3) {
+ console.log("Master: client called the callback with %s arguments:",
+ arguments.length, arg1, arg2, arg3);
+ worker.terminate();
});
View
22 lib/backgrounder.js
@@ -127,15 +127,17 @@ module.exports.spawn = function(module, callback, config) {
var child = new Child(module);
if (!config) {
- callback(child);
- return;
+ if (callback) {
+ callback(child);
+ }
}
-
- sendMessage(child, {
- "type": "config",
- "content": config
- }, function(){
- callback(child);
-
- });
+ else {
+ sendMessage(child, {
+ "type": "config",
+ "content": config
+ }, function(){
+ callback(child);
+ });
+ }
+ return child;
};

0 comments on commit acbd9e3

Please sign in to comment.