-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathworker.js
More file actions
33 lines (26 loc) · 735 Bytes
/
worker.js
File metadata and controls
33 lines (26 loc) · 735 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
/* TODO: Take this code duplication out when NODE_PATH in env works */
var path = require("path");
exports.testDir = path.dirname(__filename);
exports.libDir = path.join(exports.testDir, "../../lib");
require.paths.unshift(exports.libDir);
var sys = require("sys");
var worker = require("worker").worker;
worker.onmessage = function (msg) {
if(msg.wait) {
setTimeout(function () {
worker.postMessage("Waited")
}, 1000)
return;
}
if(msg.error) {
throw("ErrorMarker");
}
if(msg.exitCode) {
process.exit(msg.exitCode);
return;
}
msg.output = msg.input * 3;
setTimeout(function () {
worker.postMessage(msg);
}, 100 * msg.output)
};