1 | 'use strict';
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, '__esModule', {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.default = void 0;
|
---|
7 |
|
---|
8 | var _BaseWorkerPool = _interopRequireDefault(require('./base/BaseWorkerPool'));
|
---|
9 |
|
---|
10 | function _interopRequireDefault(obj) {
|
---|
11 | return obj && obj.__esModule ? obj : {default: obj};
|
---|
12 | }
|
---|
13 |
|
---|
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 | const canUseWorkerThreads = () => {
|
---|
21 | try {
|
---|
22 | require('worker_threads');
|
---|
23 |
|
---|
24 | return true;
|
---|
25 | } catch {
|
---|
26 | return false;
|
---|
27 | }
|
---|
28 | };
|
---|
29 |
|
---|
30 | class WorkerPool extends _BaseWorkerPool.default {
|
---|
31 | send(workerId, request, onStart, onEnd, onCustomMessage) {
|
---|
32 | this.getWorkerById(workerId).send(request, onStart, onEnd, onCustomMessage);
|
---|
33 | }
|
---|
34 |
|
---|
35 | createWorker(workerOptions) {
|
---|
36 | let Worker;
|
---|
37 |
|
---|
38 | if (this._options.enableWorkerThreads && canUseWorkerThreads()) {
|
---|
39 | Worker = require('./workers/NodeThreadsWorker').default;
|
---|
40 | } else {
|
---|
41 | Worker = require('./workers/ChildProcessWorker').default;
|
---|
42 | }
|
---|
43 |
|
---|
44 | return new Worker(workerOptions);
|
---|
45 | }
|
---|
46 | }
|
---|
47 |
|
---|
48 | var _default = WorkerPool;
|
---|
49 | exports.default = _default;
|
---|