1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', {
|
4 | value: true
|
5 | });
|
6 | exports.default = messageParent;
|
7 |
|
8 | function _worker_threads() {
|
9 | const data = require('worker_threads');
|
10 |
|
11 | _worker_threads = function () {
|
12 | return data;
|
13 | };
|
14 |
|
15 | return data;
|
16 | }
|
17 |
|
18 | var _types = require('../types');
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | function messageParent(message, parentProcess = process) {
|
27 | if (!_worker_threads().isMainThread && _worker_threads().parentPort != null) {
|
28 | _worker_threads().parentPort.postMessage([
|
29 | _types.PARENT_MESSAGE_CUSTOM,
|
30 | message
|
31 | ]);
|
32 | } else if (typeof parentProcess.send === 'function') {
|
33 | parentProcess.send([_types.PARENT_MESSAGE_CUSTOM, message]);
|
34 | } else {
|
35 | throw new Error('"messageParent" can only be used inside a worker');
|
36 | }
|
37 | }
|