1 | "use strict";
|
---|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
3 | exports.kFieldCount = exports.kResponseCountField = exports.kRequestCountField = exports.isTaskQueue = exports.markMovable = exports.isMovable = exports.isTransferable = exports.kQueueOptions = exports.kValue = exports.kTransferable = exports.commonState = void 0;
|
---|
4 | ;
|
---|
5 | exports.commonState = {
|
---|
6 | isWorkerThread: false,
|
---|
7 | workerData: undefined
|
---|
8 | };
|
---|
9 | // Internal symbol used to mark Transferable objects returned
|
---|
10 | // by the Piscina.move() function
|
---|
11 | const kMovable = Symbol('Piscina.kMovable');
|
---|
12 | exports.kTransferable = Symbol.for('Piscina.transferable');
|
---|
13 | exports.kValue = Symbol.for('Piscina.valueOf');
|
---|
14 | exports.kQueueOptions = Symbol.for('Piscina.queueOptions');
|
---|
15 | // True if the object implements the Transferable interface
|
---|
16 | function isTransferable(value) {
|
---|
17 | return value != null &&
|
---|
18 | typeof value === 'object' &&
|
---|
19 | exports.kTransferable in value &&
|
---|
20 | exports.kValue in value;
|
---|
21 | }
|
---|
22 | exports.isTransferable = isTransferable;
|
---|
23 | // True if object implements Transferable and has been returned
|
---|
24 | // by the Piscina.move() function
|
---|
25 | function isMovable(value) {
|
---|
26 | return isTransferable(value) && value[kMovable] === true;
|
---|
27 | }
|
---|
28 | exports.isMovable = isMovable;
|
---|
29 | function markMovable(value) {
|
---|
30 | Object.defineProperty(value, kMovable, {
|
---|
31 | enumerable: false,
|
---|
32 | configurable: true,
|
---|
33 | writable: true,
|
---|
34 | value: true
|
---|
35 | });
|
---|
36 | }
|
---|
37 | exports.markMovable = markMovable;
|
---|
38 | function isTaskQueue(value) {
|
---|
39 | return typeof value === 'object' &&
|
---|
40 | value !== null &&
|
---|
41 | 'size' in value &&
|
---|
42 | typeof value.shift === 'function' &&
|
---|
43 | typeof value.remove === 'function' &&
|
---|
44 | typeof value.push === 'function';
|
---|
45 | }
|
---|
46 | exports.isTaskQueue = isTaskQueue;
|
---|
47 | exports.kRequestCountField = 0;
|
---|
48 | exports.kResponseCountField = 1;
|
---|
49 | exports.kFieldCount = 2;
|
---|
50 | //# sourceMappingURL=common.js.map |
---|