1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const __1 = require("..");
|
4 | function launch(handler, options) {
|
5 | return __1.launch(endpointForParentProcess(), handler, options);
|
6 | }
|
7 | exports.launch = launch;
|
8 | function connect(child, options) {
|
9 | return __1.connect(endpointForChildProcess(child), options);
|
10 | }
|
11 | exports.connect = connect;
|
12 | function endpointForParentProcess() {
|
13 | if (!process.send) {
|
14 | throw new Error('`endpointForParentProcess` is only available in node processes that were `fork`ed from a parent.');
|
15 | }
|
16 | return {
|
17 | addListener: callback => process.addListener('message', callback),
|
18 | removeListener: callback => process.removeListener('message', callback),
|
19 | send: message => process.send(message),
|
20 | disconnect: () => process.disconnect()
|
21 | };
|
22 | }
|
23 | exports.endpointForParentProcess = endpointForParentProcess;
|
24 | function endpointForChildProcess(child) {
|
25 | return {
|
26 | addListener: callback => child.addListener('message', callback),
|
27 | removeListener: callback => child.removeListener('message', callback),
|
28 | send: message => child.send(message),
|
29 | disconnect: () => child.disconnect()
|
30 | };
|
31 | }
|
32 | exports.endpointForChildProcess = endpointForChildProcess;
|