messageParent.js 963 B

12345678910111213141516171819202122232425262728293031323334353637
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = messageParent;
  6. function _worker_threads() {
  7. const data = require('worker_threads');
  8. _worker_threads = function () {
  9. return data;
  10. };
  11. return data;
  12. }
  13. var _types = require('../types');
  14. /**
  15. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  16. *
  17. * This source code is licensed under the MIT license found in the
  18. * LICENSE file in the root directory of this source tree.
  19. */
  20. function messageParent(message, parentProcess = process) {
  21. if (!_worker_threads().isMainThread && _worker_threads().parentPort != null) {
  22. _worker_threads().parentPort.postMessage([
  23. _types.PARENT_MESSAGE_CUSTOM,
  24. message
  25. ]);
  26. } else if (typeof parentProcess.send === 'function') {
  27. parentProcess.send([_types.PARENT_MESSAGE_CUSTOM, message]);
  28. } else {
  29. throw new Error('"messageParent" can only be used inside a worker');
  30. }
  31. }