-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
33 lines (28 loc) · 829 Bytes
/
index.js
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
module.exports = function isolatable() {
function isolatable(master) {
if (master.isWorker) {
master.isolateWorker = function(timeout) {
try {
this.worker.timeout = timeout || this.worker.timeout;
this.server.close();
this.call('isolateWorker');
} catch (e) {
// server.close() throws an exception when called twice on the same
// server, safe to ignore. Two requests got into one worker.
}
};
return;
}
master.isolateWorker = function(worker) {
if (!worker) {
return;
}
worker.proc.kill('SIGQUIT');
master.removeWorker(worker.id);
master.emit('worker removed', worker);
master.spawnWorker(worker.id);
};
};
isolatable.enableInWorker = true;
return isolatable;
};