UNPKG

963 BJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', {
4 value: true
5});
6exports.default = messageParent;
7
8function _worker_threads() {
9 const data = require('worker_threads');
10
11 _worker_threads = function () {
12 return data;
13 };
14
15 return data;
16}
17
18var _types = require('../types');
19
20/**
21 * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
22 *
23 * This source code is licensed under the MIT license found in the
24 * LICENSE file in the root directory of this source tree.
25 */
26function 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}