-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample-slave.js
More file actions
44 lines (35 loc) · 863 Bytes
/
Copy pathexample-slave.js
File metadata and controls
44 lines (35 loc) · 863 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
var sys = require("sys");
var workerpool = require("./workerpool");
var maths = new workerpool.Worker(function (action, data) {
var self = this;
var funcDone = function() {
self.jobDone();
}
switch (action) {
case "add":
this.saveResult(data.op1 + data.op2);
break;
case "sub":
this.saveResult(data.op1 - data.op2);
break;
case "mul":
this.saveResult(data.op1 * data.op2);
break;
case "div":
this.saveResult(data.op1 / data.op2);
break;
default:
this.saveError({ error: 1, desc: "Unrecognized action: \"" + action + "\"" });
break;
}
if ((Math.floor(Math.random() * 10) + 1) < 3) {
// sys.debug("worker quitting!");
process.exit(0);
}
else if ((Math.floor(Math.random() * 10) + 1) < 3) {
// sys.debug("worker timing out!");
setTimeout(funcDone, 5000);
} else {
setTimeout(funcDone, 500);
}
});