@parcel/workers 2.0.0-nightly.92 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- 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/test/workerfarm.js
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
import Logger from '@parcel/logger';
|
2
2
|
import assert from 'assert';
|
3
|
-
import WorkerFarm from '../';
|
3
|
+
import WorkerFarm from '../src';
|
4
4
|
|
5
|
-
describe('WorkerFarm', function() {
|
6
|
-
this.timeout(
|
5
|
+
describe('WorkerFarm', function () {
|
6
|
+
this.timeout(30000);
|
7
7
|
|
8
8
|
it('Should start up workers', async () => {
|
9
9
|
let workerfarm = new WorkerFarm({
|
@@ -132,7 +132,7 @@ describe('WorkerFarm', function() {
|
|
132
132
|
await workerfarm.end();
|
133
133
|
});
|
134
134
|
|
135
|
-
it('Forwards stdio from the child process and levels event source if
|
135
|
+
it('Forwards stdio from the child process and levels event source if shouldPatchConsole is true', async () => {
|
136
136
|
let events = [];
|
137
137
|
let logDisposable = Logger.onLog(event => events.push(event));
|
138
138
|
|
@@ -140,7 +140,7 @@ describe('WorkerFarm', function() {
|
|
140
140
|
warmWorkers: true,
|
141
141
|
useLocalWorker: false,
|
142
142
|
workerPath: require.resolve('./integration/workerfarm/console.js'),
|
143
|
-
|
143
|
+
shouldPatchConsole: true,
|
144
144
|
});
|
145
145
|
|
146
146
|
await workerfarm.run();
|
@@ -291,6 +291,25 @@ describe('WorkerFarm', function() {
|
|
291
291
|
assert.equal(result, 'Shared reference does not exist');
|
292
292
|
});
|
293
293
|
|
294
|
+
it('Should resolve shared references in workers', async () => {
|
295
|
+
let workerfarm = new WorkerFarm({
|
296
|
+
warmWorkers: true,
|
297
|
+
useLocalWorker: false,
|
298
|
+
workerPath: require.resolve(
|
299
|
+
'./integration/workerfarm/resolve-shared-reference.js',
|
300
|
+
),
|
301
|
+
});
|
302
|
+
|
303
|
+
let sharedValue = 'Something to be shared';
|
304
|
+
let {ref, dispose} = await workerfarm.createSharedReference(sharedValue);
|
305
|
+
|
306
|
+
assert.equal(workerfarm.workerApi.resolveSharedReference(sharedValue), ref);
|
307
|
+
assert.ok(await workerfarm.run(ref));
|
308
|
+
|
309
|
+
await dispose();
|
310
|
+
assert(workerfarm.workerApi.resolveSharedReference(sharedValue) == null);
|
311
|
+
});
|
312
|
+
|
294
313
|
it('Should support shared references in local worker', async () => {
|
295
314
|
let workerfarm = new WorkerFarm({
|
296
315
|
warmWorkers: true,
|
@@ -309,6 +328,25 @@ describe('WorkerFarm', function() {
|
|
309
328
|
assert.equal(result, 'Shared reference does not exist');
|
310
329
|
});
|
311
330
|
|
331
|
+
it('should resolve shared references in local worker', async () => {
|
332
|
+
let workerfarm = new WorkerFarm({
|
333
|
+
warmWorkers: true,
|
334
|
+
useLocalWorker: true,
|
335
|
+
workerPath: require.resolve(
|
336
|
+
'./integration/workerfarm/resolve-shared-reference.js',
|
337
|
+
),
|
338
|
+
});
|
339
|
+
|
340
|
+
let sharedValue = 'Something to be shared';
|
341
|
+
let {ref, dispose} = await workerfarm.createSharedReference(sharedValue);
|
342
|
+
|
343
|
+
assert.equal(workerfarm.workerApi.resolveSharedReference(sharedValue), ref);
|
344
|
+
assert.ok(await workerfarm.run(ref));
|
345
|
+
|
346
|
+
await dispose();
|
347
|
+
assert(workerfarm.workerApi.resolveSharedReference(sharedValue) == null);
|
348
|
+
});
|
349
|
+
|
312
350
|
it('Should dispose of shared references when ending', async () => {
|
313
351
|
let workerfarm = new WorkerFarm({
|
314
352
|
warmWorkers: true,
|