Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added error handler 'causalty'

  • Loading branch information...
commit d532ae020d95f77bcf7b0f498b86033c8e1055b0 1 parent 89464c2
Andrew Maurer authored
Showing with 21 additions and 6 deletions.
  1. +6 −0 example.js
  2. +1 −2  minion.js
  3. +1 −1  package.json
  4. +13 −3 spawn-minions.js
6 example.js
View
@@ -18,6 +18,10 @@ var sp = new SpawnMinions();
["./minion.js", "testing12"],
["./minion.js", "testing13"]
)
+ // Executed when a message or data is sent from the process. Used for sending back data instead of text
+ .causalty(function(e){
+ console.log("error", e.toString());
+ })
// Executed when the thread reports STDOUT data event
.signalFlare(function(pos, messageData, data){
// REMOVE THIS TO SEE EACH PROCESSES RESULT
@@ -40,6 +44,8 @@ var sp = new SpawnMinions();
console.log(e); // Error
});
+// Remove this to see the queue
+return;
var queueCheck = setInterval(function(){
console.log("queue - " + sp.queue.length); // waiting to process
console.log("processQueue - " + sp.processQueue.length); // in process
3  minion.js
View
@@ -1,5 +1,4 @@
var timeDur = Math.random(2000, 5000) * 10000;
-console.log(timeDur)
setTimeout(function(){
- console.log(process.argv)
+ console.log(timeDur)
}, timeDur);
2  package.json
View
@@ -2,7 +2,7 @@
"name" : "spawn-minion"
,"author" : "Andrew Maurer <andrew@maurer.me>"
,"description" : "A module that spawns new threads for each argument passed to it. Creates a queue and limits the number of running processes to CPU count."
- ,"version" : "0.2.3"
+ ,"version" : "0.2.4"
,"main" : "spawn-minions.js"
, "repository" : {
"type" : "git"
16 spawn-minions.js
View
@@ -9,7 +9,8 @@ function SpawnMinions(){
this.finishedQueue = [];
this._cb = {
report : function(){},
- done : function(){}
+ done : function(){},
+ incomingData : function(){}
};
this.uuid = require("node-uuid");
};
@@ -18,10 +19,10 @@ SpawnMinions.prototype.armyGo = function() {
/*
arguments pattern
- [
+ (
[path, arg, arg],
[path, arg, arg]
- ]
+ )
*/
// copy args for queue
@@ -51,6 +52,11 @@ SpawnMinions.prototype.signalFlare = function(cb) {
return this;
};
+SpawnMinions.prototype.causalty = function(cb) {
+ this._cb.errorHandler = cb;
+ return this;
+};
+
SpawnMinions.prototype.warReport = function(cb) {
this._cb.report = cb;
return this;
@@ -102,6 +108,10 @@ SpawnMinions.prototype.processJob = function() {
self._cb.incomingData(job.pos, stringdata, job.data);
});
+ node.stderr.on("data", function(){
+ self._cb.errorHandler.apply(this, arguments)
+ });
+
node.on("close", function(e, param){
var processPos = self.getJob("processQueue", jobUID);
var job = self.processQueue.splice(processPos, 1)[0];
Please sign in to comment.
Something went wrong with that request. Please try again.