@parcel/workers 2.0.0-nightly.92 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +22 -0
- package/lib/Handle.js +14 -45
- package/lib/Profiler.js +20 -10
- package/lib/Trace.js +16 -11
- package/lib/Worker.js +96 -26
- package/lib/WorkerFarm.js +200 -92
- package/lib/backend.js +6 -0
- package/lib/bus.js +10 -2
- package/lib/child.js +116 -60
- package/lib/cpuCount.js +27 -6
- package/lib/index.js +24 -8
- package/lib/process/ProcessChild.js +21 -11
- package/lib/process/ProcessWorker.js +30 -19
- package/lib/threads/ThreadsChild.js +32 -14
- package/lib/threads/ThreadsWorker.js +28 -16
- package/package.json +13 -7
- package/src/Handle.js +10 -39
- package/src/Profiler.js +1 -1
- package/src/Trace.js +8 -4
- package/src/Worker.js +74 -11
- package/src/WorkerFarm.js +155 -38
- package/src/backend.js +6 -0
- package/src/bus.js +1 -1
- package/src/child.js +75 -19
- package/src/cpuCount.js +9 -4
- package/src/index.js +1 -1
- package/src/process/ProcessChild.js +1 -1
- package/src/process/ProcessWorker.js +1 -1
- package/src/threads/ThreadsWorker.js +2 -2
- package/test/cpuCount.test.js +1 -1
- package/test/integration/workerfarm/console.js +1 -1
- package/test/integration/workerfarm/logging.js +1 -1
- package/test/integration/workerfarm/resolve-shared-reference.js +5 -0
- package/test/integration/workerfarm/reverse-handle.js +2 -2
- package/test/workerfarm.js +43 -5
package/lib/child.js
CHANGED
@@ -5,72 +5,102 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.Child = void 0;
|
7
7
|
|
8
|
-
|
8
|
+
function _assert() {
|
9
|
+
const data = _interopRequireDefault(require("assert"));
|
9
10
|
|
10
|
-
|
11
|
+
_assert = function () {
|
12
|
+
return data;
|
13
|
+
};
|
11
14
|
|
12
|
-
|
13
|
-
|
14
|
-
var _diagnostic = _interopRequireWildcard(require("@parcel/diagnostic"));
|
15
|
-
|
16
|
-
var _bus = _interopRequireDefault(require("./bus"));
|
17
|
-
|
18
|
-
var _Profiler = _interopRequireDefault(require("./Profiler"));
|
15
|
+
return data;
|
16
|
+
}
|
19
17
|
|
20
|
-
|
18
|
+
function _nullthrows() {
|
19
|
+
const data = _interopRequireDefault(require("nullthrows"));
|
21
20
|
|
22
|
-
|
21
|
+
_nullthrows = function () {
|
22
|
+
return data;
|
23
|
+
};
|
23
24
|
|
24
|
-
|
25
|
+
return data;
|
26
|
+
}
|
25
27
|
|
26
|
-
function
|
28
|
+
function _logger() {
|
29
|
+
const data = _interopRequireWildcard(require("@parcel/logger"));
|
27
30
|
|
28
|
-
|
31
|
+
_logger = function () {
|
32
|
+
return data;
|
33
|
+
};
|
29
34
|
|
30
|
-
|
35
|
+
return data;
|
36
|
+
}
|
31
37
|
|
32
|
-
function
|
38
|
+
function _diagnostic() {
|
39
|
+
const data = _interopRequireWildcard(require("@parcel/diagnostic"));
|
33
40
|
|
34
|
-
|
35
|
-
|
36
|
-
|
41
|
+
_diagnostic = function () {
|
42
|
+
return data;
|
43
|
+
};
|
37
44
|
|
38
|
-
|
45
|
+
return data;
|
46
|
+
}
|
39
47
|
|
40
|
-
|
48
|
+
function _core() {
|
49
|
+
const data = require("@parcel/core");
|
41
50
|
|
42
|
-
|
51
|
+
_core = function () {
|
52
|
+
return data;
|
53
|
+
};
|
43
54
|
|
44
|
-
|
55
|
+
return data;
|
56
|
+
}
|
45
57
|
|
46
|
-
|
58
|
+
var _bus = _interopRequireDefault(require("./bus"));
|
47
59
|
|
48
|
-
|
60
|
+
var _Profiler = _interopRequireDefault(require("./Profiler"));
|
49
61
|
|
50
|
-
|
62
|
+
var _Handle2 = _interopRequireDefault(require("./Handle"));
|
51
63
|
|
52
|
-
|
64
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
53
65
|
|
54
|
-
|
66
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
55
67
|
|
56
|
-
|
68
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
57
69
|
|
58
|
-
|
70
|
+
// The import of './Handle' should really be imported eagerly (with @babel/plugin-transform-modules-commonjs's lazy mode).
|
71
|
+
const Handle = _Handle2.default;
|
59
72
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
73
|
+
class Child {
|
74
|
+
callQueue = [];
|
75
|
+
maxConcurrentCalls = 10;
|
76
|
+
responseId = 0;
|
77
|
+
responseQueue = new Map();
|
78
|
+
handles = new Map();
|
79
|
+
sharedReferences = new Map();
|
80
|
+
sharedReferencesByValue = new Map();
|
65
81
|
|
66
|
-
|
82
|
+
constructor(ChildBackend) {
|
83
|
+
this.child = new ChildBackend(m => {
|
84
|
+
this.messageListener(m);
|
85
|
+
}, () => this.handleEnd()); // Monitior all logging events inside this child process and forward to
|
67
86
|
// the main process via the bus.
|
68
87
|
|
69
|
-
this.loggerDisposable = _logger.default.onLog(event => {
|
88
|
+
this.loggerDisposable = _logger().default.onLog(event => {
|
70
89
|
_bus.default.emit('logEvent', event);
|
71
90
|
});
|
72
91
|
}
|
73
92
|
|
93
|
+
workerApi = {
|
94
|
+
callMaster: (request, awaitResponse = true) => this.addCall(request, awaitResponse),
|
95
|
+
createReverseHandle: fn => this.createReverseHandle(fn),
|
96
|
+
runHandle: (handle, args) => this.workerApi.callMaster({
|
97
|
+
handle: handle.id,
|
98
|
+
args
|
99
|
+
}, true),
|
100
|
+
getSharedReference: ref => this.sharedReferences.get(ref),
|
101
|
+
resolveSharedReference: value => this.sharedReferencesByValue.get(value)
|
102
|
+
};
|
103
|
+
|
74
104
|
messageListener(message) {
|
75
105
|
if (message.type === 'response') {
|
76
106
|
return this.handleResponse(message);
|
@@ -83,10 +113,14 @@ class Child {
|
|
83
113
|
this.child.send(data);
|
84
114
|
}
|
85
115
|
|
86
|
-
childInit(module, childId) {
|
116
|
+
async childInit(module, childId) {
|
87
117
|
// $FlowFixMe this must be dynamic
|
88
118
|
this.module = require(module);
|
89
119
|
this.childId = childId;
|
120
|
+
|
121
|
+
if (this.module.childInit != null) {
|
122
|
+
await this.module.childInit();
|
123
|
+
}
|
90
124
|
}
|
91
125
|
|
92
126
|
async handleRequest(data) {
|
@@ -96,7 +130,7 @@ class Child {
|
|
96
130
|
args,
|
97
131
|
handle: handleId
|
98
132
|
} = data;
|
99
|
-
let child = (0, _nullthrows.default)(data.child);
|
133
|
+
let child = (0, _nullthrows().default)(data.child);
|
100
134
|
|
101
135
|
const responseFromContent = content => ({
|
102
136
|
idx,
|
@@ -111,14 +145,16 @@ class Child {
|
|
111
145
|
child,
|
112
146
|
type: 'response',
|
113
147
|
contentType: 'error',
|
114
|
-
content: (0, _diagnostic.anyToDiagnostic)(e)
|
148
|
+
content: (0, _diagnostic().anyToDiagnostic)(e)
|
115
149
|
});
|
116
150
|
|
117
151
|
let result;
|
118
152
|
|
119
153
|
if (handleId != null) {
|
120
154
|
try {
|
121
|
-
|
155
|
+
var _this$handles$get;
|
156
|
+
|
157
|
+
let fn = (0, _nullthrows().default)((_this$handles$get = this.handles.get(handleId)) === null || _this$handles$get === void 0 ? void 0 : _this$handles$get.fn);
|
122
158
|
result = responseFromContent(fn(...args));
|
123
159
|
} catch (e) {
|
124
160
|
result = errorResponseFromError(e);
|
@@ -127,13 +163,13 @@ class Child {
|
|
127
163
|
try {
|
128
164
|
let [moduleName, childOptions] = args;
|
129
165
|
|
130
|
-
if (childOptions.
|
131
|
-
(0, _logger.patchConsole)();
|
166
|
+
if (childOptions.shouldPatchConsole) {
|
167
|
+
(0, _logger().patchConsole)();
|
132
168
|
} else {
|
133
|
-
(0, _logger.unpatchConsole)();
|
169
|
+
(0, _logger().unpatchConsole)();
|
134
170
|
}
|
135
171
|
|
136
|
-
result = responseFromContent(this.childInit(moduleName, child));
|
172
|
+
result = responseFromContent(await this.childInit(moduleName, child));
|
137
173
|
} catch (e) {
|
138
174
|
result = errorResponseFromError(e);
|
139
175
|
}
|
@@ -141,7 +177,7 @@ class Child {
|
|
141
177
|
this.profiler = new _Profiler.default();
|
142
178
|
|
143
179
|
try {
|
144
|
-
result = responseFromContent(
|
180
|
+
result = responseFromContent(await this.profiler.startProfiling());
|
145
181
|
} catch (e) {
|
146
182
|
result = errorResponseFromError(e);
|
147
183
|
}
|
@@ -152,33 +188,54 @@ class Child {
|
|
152
188
|
} catch (e) {
|
153
189
|
result = errorResponseFromError(e);
|
154
190
|
}
|
191
|
+
} else if (method === 'takeHeapSnapshot') {
|
192
|
+
try {
|
193
|
+
let v8 = require('v8');
|
194
|
+
|
195
|
+
result = responseFromContent( // $FlowFixMe
|
196
|
+
v8.writeHeapSnapshot('heap-' + args[0] + '-' + (this.childId ? 'worker' + this.childId : 'main') + '.heapsnapshot'));
|
197
|
+
} catch (e) {
|
198
|
+
result = errorResponseFromError(e);
|
199
|
+
}
|
155
200
|
} else if (method === 'createSharedReference') {
|
156
|
-
|
201
|
+
let [ref, _value] = args;
|
202
|
+
let value = _value instanceof ArrayBuffer ? // In the case the value is pre-serialized as a buffer,
|
203
|
+
// deserialize it.
|
204
|
+
(0, _core().deserialize)(Buffer.from(_value)) : _value;
|
205
|
+
this.sharedReferences.set(ref, value);
|
206
|
+
this.sharedReferencesByValue.set(value, ref);
|
157
207
|
result = responseFromContent(null);
|
158
208
|
} else if (method === 'deleteSharedReference') {
|
159
|
-
|
209
|
+
let ref = args[0];
|
210
|
+
let value = this.sharedReferences.get(ref);
|
211
|
+
this.sharedReferencesByValue.delete(value);
|
212
|
+
this.sharedReferences.delete(ref);
|
160
213
|
result = responseFromContent(null);
|
161
214
|
} else {
|
162
215
|
try {
|
163
|
-
result = responseFromContent(
|
164
|
-
await this.module[method](this.workerApi, ...args))
|
216
|
+
result = responseFromContent( // $FlowFixMe
|
217
|
+
await this.module[method](this.workerApi, ...args));
|
165
218
|
} catch (e) {
|
166
219
|
result = errorResponseFromError(e);
|
167
220
|
}
|
168
221
|
}
|
169
222
|
|
170
|
-
|
223
|
+
try {
|
224
|
+
this.send(result);
|
225
|
+
} catch (e) {
|
226
|
+
result = this.send(errorResponseFromError(e));
|
227
|
+
}
|
171
228
|
}
|
172
229
|
|
173
230
|
handleResponse(data) {
|
174
|
-
let idx = (0, _nullthrows.default)(data.idx);
|
231
|
+
let idx = (0, _nullthrows().default)(data.idx);
|
175
232
|
let contentType = data.contentType;
|
176
233
|
let content = data.content;
|
177
|
-
let call = (0, _nullthrows.default)(this.responseQueue.get(idx));
|
234
|
+
let call = (0, _nullthrows().default)(this.responseQueue.get(idx));
|
178
235
|
|
179
236
|
if (contentType === 'error') {
|
180
|
-
(0, _assert.default)(typeof content !== 'string');
|
181
|
-
call.reject(new _diagnostic.default({
|
237
|
+
(0, _assert().default)(typeof content !== 'string');
|
238
|
+
call.reject(new (_diagnostic().default)({
|
182
239
|
diagnostic: content
|
183
240
|
}));
|
184
241
|
} else {
|
@@ -195,14 +252,14 @@ class Child {
|
|
195
252
|
var _promise;
|
196
253
|
|
197
254
|
// $FlowFixMe
|
198
|
-
let call =
|
255
|
+
let call = { ...request,
|
199
256
|
type: 'request',
|
200
257
|
child: this.childId,
|
258
|
+
// $FlowFixMe Added in Flow 0.121.0 upgrade in #4381
|
201
259
|
awaitResponse,
|
202
260
|
resolve: () => {},
|
203
261
|
reject: () => {}
|
204
|
-
}
|
205
|
-
|
262
|
+
};
|
206
263
|
let promise;
|
207
264
|
|
208
265
|
if (awaitResponse) {
|
@@ -252,9 +309,8 @@ class Child {
|
|
252
309
|
}
|
253
310
|
|
254
311
|
createReverseHandle(fn) {
|
255
|
-
let handle = new
|
312
|
+
let handle = new Handle({
|
256
313
|
fn,
|
257
|
-
workerApi: this.workerApi,
|
258
314
|
childId: this.childId
|
259
315
|
});
|
260
316
|
this.handles.set(handle.id, handle);
|
package/lib/cpuCount.js
CHANGED
@@ -6,15 +6,31 @@ Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
exports.detectRealCores = detectRealCores;
|
7
7
|
exports.default = getCores;
|
8
8
|
|
9
|
-
|
9
|
+
function _os() {
|
10
|
+
const data = _interopRequireDefault(require("os"));
|
10
11
|
|
11
|
-
|
12
|
+
_os = function () {
|
13
|
+
return data;
|
14
|
+
};
|
15
|
+
|
16
|
+
return data;
|
17
|
+
}
|
18
|
+
|
19
|
+
function _child_process() {
|
20
|
+
const data = require("child_process");
|
21
|
+
|
22
|
+
_child_process = function () {
|
23
|
+
return data;
|
24
|
+
};
|
25
|
+
|
26
|
+
return data;
|
27
|
+
}
|
12
28
|
|
13
29
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
14
30
|
|
15
31
|
const exec = command => {
|
16
32
|
try {
|
17
|
-
let stdout = (0, _child_process.execSync)(command, {
|
33
|
+
let stdout = (0, _child_process().execSync)(command, {
|
18
34
|
encoding: 'utf8',
|
19
35
|
// This prevents the command from outputting to the console
|
20
36
|
stdio: [null, null, null]
|
@@ -26,7 +42,7 @@ const exec = command => {
|
|
26
42
|
};
|
27
43
|
|
28
44
|
function detectRealCores() {
|
29
|
-
let platform = _os.default.platform();
|
45
|
+
let platform = _os().default.platform();
|
30
46
|
|
31
47
|
let amount = 0;
|
32
48
|
|
@@ -34,6 +50,12 @@ function detectRealCores() {
|
|
34
50
|
amount = parseInt(exec('lscpu -p | egrep -v "^#" | sort -u -t, -k 2,4 | wc -l'), 10);
|
35
51
|
} else if (platform === 'darwin') {
|
36
52
|
amount = parseInt(exec('sysctl -n hw.physicalcpu_max'), 10);
|
53
|
+
} else if (platform === 'win32') {
|
54
|
+
const str = exec('wmic cpu get NumberOfCores').match(/\d+/g);
|
55
|
+
|
56
|
+
if (str !== null) {
|
57
|
+
amount = parseInt(str.filter(n => n !== '')[0], 10);
|
58
|
+
}
|
37
59
|
}
|
38
60
|
|
39
61
|
if (!amount || amount <= 0) {
|
@@ -47,7 +69,6 @@ let cores;
|
|
47
69
|
|
48
70
|
function getCores(bypassCache = false) {
|
49
71
|
// Do not re-run commands if we already have the count...
|
50
|
-
// $FlowFixMe
|
51
72
|
if (cores && !bypassCache) {
|
52
73
|
return cores;
|
53
74
|
}
|
@@ -56,7 +77,7 @@ function getCores(bypassCache = false) {
|
|
56
77
|
cores = detectRealCores();
|
57
78
|
} catch (e) {
|
58
79
|
// Guess the amount of real cores
|
59
|
-
cores = _os.default.cpus().filter((cpu, index) => !cpu.model.includes('Intel') || index % 2 === 1).length;
|
80
|
+
cores = _os().default.cpus().filter((cpu, index) => !cpu.model.includes('Intel') || index % 2 === 1).length;
|
60
81
|
} // Another fallback
|
61
82
|
|
62
83
|
|
package/lib/index.js
CHANGED
@@ -17,11 +17,27 @@ Object.defineProperty(exports, "bus", {
|
|
17
17
|
});
|
18
18
|
exports.default = void 0;
|
19
19
|
|
20
|
-
|
20
|
+
function _assert() {
|
21
|
+
const data = _interopRequireDefault(require("assert"));
|
22
|
+
|
23
|
+
_assert = function () {
|
24
|
+
return data;
|
25
|
+
};
|
26
|
+
|
27
|
+
return data;
|
28
|
+
}
|
21
29
|
|
22
30
|
var _WorkerFarm = _interopRequireWildcard(require("./WorkerFarm"));
|
23
31
|
|
24
|
-
|
32
|
+
function _logger() {
|
33
|
+
const data = _interopRequireDefault(require("@parcel/logger"));
|
34
|
+
|
35
|
+
_logger = function () {
|
36
|
+
return data;
|
37
|
+
};
|
38
|
+
|
39
|
+
return data;
|
40
|
+
}
|
25
41
|
|
26
42
|
var _bus = _interopRequireDefault(require("./bus"));
|
27
43
|
|
@@ -36,29 +52,29 @@ if (!_WorkerFarm.default.isWorker()) {
|
|
36
52
|
_bus.default.on('logEvent', e => {
|
37
53
|
switch (e.level) {
|
38
54
|
case 'info':
|
39
|
-
_logger.default.info(e.diagnostics);
|
55
|
+
_logger().default.info(e.diagnostics);
|
40
56
|
|
41
57
|
break;
|
42
58
|
|
43
59
|
case 'progress':
|
44
|
-
(0, _assert.default)(typeof e.message === 'string');
|
60
|
+
(0, _assert().default)(typeof e.message === 'string');
|
45
61
|
|
46
|
-
_logger.default.progress(e.message);
|
62
|
+
_logger().default.progress(e.message);
|
47
63
|
|
48
64
|
break;
|
49
65
|
|
50
66
|
case 'verbose':
|
51
|
-
_logger.default.verbose(e.diagnostics);
|
67
|
+
_logger().default.verbose(e.diagnostics);
|
52
68
|
|
53
69
|
break;
|
54
70
|
|
55
71
|
case 'warn':
|
56
|
-
_logger.default.warn(e.diagnostics);
|
72
|
+
_logger().default.warn(e.diagnostics);
|
57
73
|
|
58
74
|
break;
|
59
75
|
|
60
76
|
case 'error':
|
61
|
-
_logger.default.error(e.diagnostics);
|
77
|
+
_logger().default.error(e.diagnostics);
|
62
78
|
|
63
79
|
break;
|
64
80
|
|
@@ -5,24 +5,34 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.default = void 0;
|
7
7
|
|
8
|
-
|
8
|
+
function _nullthrows() {
|
9
|
+
const data = _interopRequireDefault(require("nullthrows"));
|
10
|
+
|
11
|
+
_nullthrows = function () {
|
12
|
+
return data;
|
13
|
+
};
|
14
|
+
|
15
|
+
return data;
|
16
|
+
}
|
9
17
|
|
10
18
|
var _childState = require("../childState");
|
11
19
|
|
12
20
|
var _child = require("../child");
|
13
21
|
|
14
|
-
|
22
|
+
function _core() {
|
23
|
+
const data = require("@parcel/core");
|
15
24
|
|
16
|
-
function
|
25
|
+
_core = function () {
|
26
|
+
return data;
|
27
|
+
};
|
17
28
|
|
18
|
-
|
29
|
+
return data;
|
30
|
+
}
|
31
|
+
|
32
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
19
33
|
|
20
34
|
class ProcessChild {
|
21
35
|
constructor(onMessage, onExit) {
|
22
|
-
_defineProperty(this, "onMessage", void 0);
|
23
|
-
|
24
|
-
_defineProperty(this, "onExit", void 0);
|
25
|
-
|
26
36
|
if (!process.send) {
|
27
37
|
throw new Error('Only create ProcessChild instances in a worker!');
|
28
38
|
}
|
@@ -37,12 +47,12 @@ class ProcessChild {
|
|
37
47
|
return this.stop();
|
38
48
|
}
|
39
49
|
|
40
|
-
this.onMessage((0, _core.deserialize)(Buffer.from(data, 'base64')));
|
50
|
+
this.onMessage((0, _core().deserialize)(Buffer.from(data, 'base64')));
|
41
51
|
}
|
42
52
|
|
43
53
|
send(data) {
|
44
|
-
let processSend = (0, _nullthrows.default)(process.send).bind(process);
|
45
|
-
processSend((0, _core.serialize)(data).toString('base64'), err => {
|
54
|
+
let processSend = (0, _nullthrows().default)(process.send).bind(process);
|
55
|
+
processSend((0, _core().serialize)(data).toString('base64'), err => {
|
46
56
|
if (err && err instanceof Error) {
|
47
57
|
if (err.code === 'ERR_IPC_CHANNEL_CLOSED') {
|
48
58
|
// IPC connection closed
|
@@ -5,34 +5,45 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.default = void 0;
|
7
7
|
|
8
|
-
|
8
|
+
function _child_process() {
|
9
|
+
const data = _interopRequireDefault(require("child_process"));
|
9
10
|
|
10
|
-
|
11
|
+
_child_process = function () {
|
12
|
+
return data;
|
13
|
+
};
|
11
14
|
|
12
|
-
|
13
|
-
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15
|
+
return data;
|
16
|
+
}
|
15
17
|
|
16
|
-
function
|
18
|
+
function _path() {
|
19
|
+
const data = _interopRequireDefault(require("path"));
|
17
20
|
|
18
|
-
|
21
|
+
_path = function () {
|
22
|
+
return data;
|
23
|
+
};
|
19
24
|
|
20
|
-
|
21
|
-
|
22
|
-
_defineProperty(this, "execArgv", void 0);
|
25
|
+
return data;
|
26
|
+
}
|
23
27
|
|
24
|
-
|
28
|
+
function _core() {
|
29
|
+
const data = require("@parcel/core");
|
25
30
|
|
26
|
-
|
31
|
+
_core = function () {
|
32
|
+
return data;
|
33
|
+
};
|
27
34
|
|
28
|
-
|
35
|
+
return data;
|
36
|
+
}
|
29
37
|
|
30
|
-
|
38
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
31
39
|
|
32
|
-
|
40
|
+
const WORKER_PATH = _path().default.join(__dirname, 'ProcessChild.js');
|
33
41
|
|
34
|
-
|
42
|
+
class ProcessWorker {
|
43
|
+
processQueue = true;
|
44
|
+
sendQueue = [];
|
35
45
|
|
46
|
+
constructor(execArgv, onMessage, onError, onExit) {
|
36
47
|
this.execArgv = execArgv;
|
37
48
|
this.onMessage = onMessage;
|
38
49
|
this.onError = onError;
|
@@ -40,13 +51,13 @@ class ProcessWorker {
|
|
40
51
|
}
|
41
52
|
|
42
53
|
start() {
|
43
|
-
this.child = _child_process.default.fork(WORKER_PATH, process.argv, {
|
54
|
+
this.child = _child_process().default.fork(WORKER_PATH, process.argv, {
|
44
55
|
execArgv: this.execArgv,
|
45
56
|
env: process.env,
|
46
57
|
cwd: process.cwd()
|
47
58
|
});
|
48
59
|
this.child.on('message', data => {
|
49
|
-
this.onMessage((0, _core.deserialize)(Buffer.from(data, 'base64')));
|
60
|
+
this.onMessage((0, _core().deserialize)(Buffer.from(data, 'base64')));
|
50
61
|
});
|
51
62
|
this.child.once('exit', this.onExit);
|
52
63
|
this.child.on('error', this.onError);
|
@@ -68,7 +79,7 @@ class ProcessWorker {
|
|
68
79
|
return;
|
69
80
|
}
|
70
81
|
|
71
|
-
let result = this.child.send((0, _core.serialize)(data).toString('base64'), error => {
|
82
|
+
let result = this.child.send((0, _core().serialize)(data).toString('base64'), error => {
|
72
83
|
if (error && error instanceof Error) {
|
73
84
|
// Ignore this, the workerfarm handles child errors
|
74
85
|
return;
|
@@ -5,44 +5,62 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.default = void 0;
|
7
7
|
|
8
|
-
|
8
|
+
function _worker_threads() {
|
9
|
+
const data = require("worker_threads");
|
9
10
|
|
10
|
-
|
11
|
+
_worker_threads = function () {
|
12
|
+
return data;
|
13
|
+
};
|
14
|
+
|
15
|
+
return data;
|
16
|
+
}
|
17
|
+
|
18
|
+
function _nullthrows() {
|
19
|
+
const data = _interopRequireDefault(require("nullthrows"));
|
20
|
+
|
21
|
+
_nullthrows = function () {
|
22
|
+
return data;
|
23
|
+
};
|
24
|
+
|
25
|
+
return data;
|
26
|
+
}
|
11
27
|
|
12
28
|
var _childState = require("../childState");
|
13
29
|
|
14
30
|
var _child = require("../child");
|
15
31
|
|
16
|
-
|
32
|
+
function _core() {
|
33
|
+
const data = require("@parcel/core");
|
17
34
|
|
18
|
-
function
|
35
|
+
_core = function () {
|
36
|
+
return data;
|
37
|
+
};
|
38
|
+
|
39
|
+
return data;
|
40
|
+
}
|
19
41
|
|
20
|
-
function
|
42
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
21
43
|
|
22
44
|
class ThreadsChild {
|
23
45
|
constructor(onMessage, onExit) {
|
24
|
-
|
25
|
-
|
26
|
-
_defineProperty(this, "onExit", void 0);
|
27
|
-
|
28
|
-
if (_worker_threads.isMainThread || !_worker_threads.parentPort) {
|
46
|
+
if (_worker_threads().isMainThread || !_worker_threads().parentPort) {
|
29
47
|
throw new Error('Only create ThreadsChild instances in a worker!');
|
30
48
|
}
|
31
49
|
|
32
50
|
this.onMessage = onMessage;
|
33
51
|
this.onExit = onExit;
|
34
52
|
|
35
|
-
_worker_threads.parentPort.on('message', data => this.handleMessage(data));
|
53
|
+
_worker_threads().parentPort.on('message', data => this.handleMessage(data));
|
36
54
|
|
37
|
-
_worker_threads.parentPort.on('close', this.onExit);
|
55
|
+
_worker_threads().parentPort.on('close', this.onExit);
|
38
56
|
}
|
39
57
|
|
40
58
|
handleMessage(data) {
|
41
|
-
this.onMessage((0, _core.restoreDeserializedObject)(data));
|
59
|
+
this.onMessage((0, _core().restoreDeserializedObject)(data));
|
42
60
|
}
|
43
61
|
|
44
62
|
send(data) {
|
45
|
-
(0, _nullthrows.default)(_worker_threads.parentPort).postMessage((0, _core.prepareForSerialization)(data));
|
63
|
+
(0, _nullthrows().default)(_worker_threads().parentPort).postMessage((0, _core().prepareForSerialization)(data));
|
46
64
|
}
|
47
65
|
|
48
66
|
}
|