UNPKG

1.26 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const __1 = require("..");
4function launch(handler, options) {
5 return __1.launch(endpointForParentProcess(), handler, options);
6}
7exports.launch = launch;
8function connect(child, options) {
9 return __1.connect(endpointForChildProcess(child), options);
10}
11exports.connect = connect;
12function 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}
23exports.endpointForParentProcess = endpointForParentProcess;
24function 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}
32exports.endpointForChildProcess = endpointForChildProcess;