Skip to content

Commit a10e8da

Browse files
committed
Initial commit
1 parent 2e4b36b commit a10e8da

16 files changed

+1768
-1767
lines changed

lib/Worker.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
1-
var ps = require('child_process');
1+
/**
2+
* @flow
3+
*/
4+
const ps = require('child_process');
25

36
function Worker(url) {
4-
var that = this;
5-
this.process = ps.fork(url);
6-
this.process.on('message', function (msg) {
7-
if (that.onmessage) {
8-
that.onmessage({ data: JSON.parse(msg) });
9-
}
10-
});
11-
this.process.on('error', function (err) {
12-
if (that.onerror) {
13-
that.onerror(err);
14-
}
15-
});
7+
const that = this;
8+
this.process = ps.fork(url);
9+
this.process.on('message', (msg) => {
10+
if (that.onmessage) {
11+
that.onmessage({ data: JSON.parse(msg) });
12+
}
13+
});
14+
this.process.on('error', (err) => {
15+
if (that.onerror) {
16+
that.onerror(err);
17+
}
18+
});
1619
}
1720

1821
Worker.prototype.onmessage = null;
1922
Worker.prototype.onerror = null;
2023

2124
Worker.prototype.postMessage = function (obj) {
22-
this.process.send(JSON.stringify({ data: obj }));
25+
this.process.send(JSON.stringify({ data: obj }));
2326
};
2427

2528
Worker.prototype.terminate = function () {
26-
this.process.kill();
29+
this.process.kill();
2730
};
2831

29-
module.exports = Worker;
32+
module.exports = Worker;

lib/eval.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
var isNode = typeof module !== 'undefined' && module.exports;
1+
/**
2+
* @flow
3+
*/
4+
const isNode = typeof module !== 'undefined' && module.exports;
25

36
if (isNode) {
4-
process.once('message', function (code) {
5-
eval(JSON.parse(code).data);
6-
});
7+
process.once('message', (code) => {
8+
eval(JSON.parse(code).data);
9+
});
710
} else {
8-
self.onmessage = function (code) {
9-
eval(code.data);
10-
};
11-
}
11+
self.onmessage = function (code) {
12+
eval(code.data);
13+
};
14+
}

0 commit comments

Comments
 (0)