@loaders.gl/worker-utils 4.2.0-alpha.4 → 4.2.0-alpha.6
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/dist/index.cjs +225 -86
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +18 -18
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -8
- package/dist/lib/async-queue/async-queue.js +83 -68
- package/dist/lib/env-utils/assert.js +10 -4
- package/dist/lib/env-utils/globals.js +19 -7
- package/dist/lib/env-utils/version.js +20 -11
- package/dist/lib/library-utils/library-utils.js +148 -73
- package/dist/lib/node/require-utils.node.js +72 -43
- package/dist/lib/node/worker_threads-browser.js +9 -2
- package/dist/lib/node/worker_threads.js +4 -2
- package/dist/lib/process-utils/child-process-proxy.d.ts +1 -3
- package/dist/lib/process-utils/child-process-proxy.d.ts.map +1 -1
- package/dist/lib/process-utils/child-process-proxy.js +103 -93
- package/dist/lib/process-utils/process-utils.js +28 -23
- package/dist/lib/worker-api/create-worker.d.ts +1 -1
- package/dist/lib/worker-api/create-worker.d.ts.map +1 -1
- package/dist/lib/worker-api/create-worker.js +77 -74
- package/dist/lib/worker-api/get-worker-url.d.ts +1 -1
- package/dist/lib/worker-api/get-worker-url.d.ts.map +1 -1
- package/dist/lib/worker-api/get-worker-url.js +52 -26
- package/dist/lib/worker-api/process-on-worker.d.ts +1 -1
- package/dist/lib/worker-api/process-on-worker.d.ts.map +1 -1
- package/dist/lib/worker-api/process-on-worker.js +70 -67
- package/dist/lib/worker-api/validate-worker-version.d.ts +1 -1
- package/dist/lib/worker-api/validate-worker-version.d.ts.map +1 -1
- package/dist/lib/worker-api/validate-worker-version.js +29 -14
- package/dist/lib/worker-farm/worker-body.d.ts +1 -1
- package/dist/lib/worker-farm/worker-body.d.ts.map +1 -1
- package/dist/lib/worker-farm/worker-body.js +109 -68
- package/dist/lib/worker-farm/worker-farm.d.ts +1 -1
- package/dist/lib/worker-farm/worker-farm.d.ts.map +1 -1
- package/dist/lib/worker-farm/worker-farm.js +80 -62
- package/dist/lib/worker-farm/worker-job.d.ts +2 -2
- package/dist/lib/worker-farm/worker-job.d.ts.map +1 -1
- package/dist/lib/worker-farm/worker-job.js +48 -32
- package/dist/lib/worker-farm/worker-pool.d.ts +3 -3
- package/dist/lib/worker-farm/worker-pool.d.ts.map +1 -1
- package/dist/lib/worker-farm/worker-pool.js +153 -111
- package/dist/lib/worker-farm/worker-thread.d.ts +1 -1
- package/dist/lib/worker-farm/worker-thread.d.ts.map +1 -1
- package/dist/lib/worker-farm/worker-thread.js +126 -94
- package/dist/lib/worker-utils/get-loadable-worker-url.js +54 -24
- package/dist/lib/worker-utils/get-transfer-list.js +79 -44
- package/dist/lib/worker-utils/remove-nontransferable-options.js +23 -14
- package/dist/null-worker-node.js +6 -1
- package/dist/null-worker-node.js.map +2 -2
- package/dist/null-worker.js +3 -1
- package/dist/null-worker.js.map +2 -2
- package/dist/types.js +3 -1
- package/dist/workers/null-worker.js +6 -3
- package/package.json +11 -11
- package/src/lib/process-utils/child-process-proxy.ts +1 -1
- package/src/lib/worker-farm/worker-body.ts +7 -2
- package/dist/index.js.map +0 -1
- package/dist/lib/async-queue/async-queue.js.map +0 -1
- package/dist/lib/env-utils/assert.js.map +0 -1
- package/dist/lib/env-utils/globals.js.map +0 -1
- package/dist/lib/env-utils/version.js.map +0 -1
- package/dist/lib/library-utils/library-utils.js.map +0 -1
- package/dist/lib/node/require-utils.node.js.map +0 -1
- package/dist/lib/node/worker_threads-browser.js.map +0 -1
- package/dist/lib/node/worker_threads.js.map +0 -1
- package/dist/lib/process-utils/child-process-proxy.js.map +0 -1
- package/dist/lib/process-utils/process-utils.js.map +0 -1
- package/dist/lib/worker-api/create-worker.js.map +0 -1
- package/dist/lib/worker-api/get-worker-url.js.map +0 -1
- package/dist/lib/worker-api/process-on-worker.js.map +0 -1
- package/dist/lib/worker-api/validate-worker-version.js.map +0 -1
- package/dist/lib/worker-farm/worker-body.js.map +0 -1
- package/dist/lib/worker-farm/worker-farm.js.map +0 -1
- package/dist/lib/worker-farm/worker-job.js.map +0 -1
- package/dist/lib/worker-farm/worker-pool.js.map +0 -1
- package/dist/lib/worker-farm/worker-thread.js.map +0 -1
- package/dist/lib/worker-utils/get-loadable-worker-url.js.map +0 -1
- package/dist/lib/worker-utils/get-transfer-list.js.map +0 -1
- package/dist/lib/worker-utils/remove-nontransferable-options.js.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/workers/null-worker.js.map +0 -1
|
@@ -1,83 +1,124 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
import { getTransferList } from "../worker-utils/get-transfer-list.js";
|
|
5
|
+
// import type {TransferListItem} from '../node/worker_threads';
|
|
2
6
|
import { parentPort } from "../node/worker_threads.js";
|
|
7
|
+
/** Vile hack to defeat over-zealous bundlers from stripping out the require */
|
|
3
8
|
async function getParentPort() {
|
|
4
|
-
|
|
9
|
+
// const isNode = globalThis.process;
|
|
10
|
+
// let parentPort;
|
|
11
|
+
// try {
|
|
12
|
+
// // prettier-ignore
|
|
13
|
+
// eval('globalThis.parentPort = require(\'worker_threads\').parentPort'); // eslint-disable-line no-eval
|
|
14
|
+
// parentPort = globalThis.parentPort;
|
|
15
|
+
// } catch {
|
|
16
|
+
// try {
|
|
17
|
+
// // prettier-ignore
|
|
18
|
+
// eval('globalThis.workerThreadsPromise = import(\'worker_threads\')'); // eslint-disable-line no-eval
|
|
19
|
+
// const workerThreads = await globalThis.workerThreadsPromise;
|
|
20
|
+
// parentPort = workerThreads.parentPort;
|
|
21
|
+
// } catch (error) {
|
|
22
|
+
// console.error((error as Error).message); // eslint-disable-line no-console
|
|
23
|
+
// }
|
|
24
|
+
// }
|
|
25
|
+
return parentPort;
|
|
5
26
|
}
|
|
6
27
|
const onMessageWrapperMap = new Map();
|
|
28
|
+
/**
|
|
29
|
+
* Type safe wrapper for worker code
|
|
30
|
+
*/
|
|
7
31
|
export default class WorkerBody {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
static set onmessage(onMessage) {
|
|
12
|
-
async function handleMessage(message) {
|
|
13
|
-
const parentPort = await getParentPort();
|
|
14
|
-
const {
|
|
15
|
-
type,
|
|
16
|
-
payload
|
|
17
|
-
} = parentPort ? message : message.data;
|
|
18
|
-
onMessage(type, payload);
|
|
32
|
+
/** Check that we are actually in a worker thread */
|
|
33
|
+
static async inWorkerThread() {
|
|
34
|
+
return typeof self !== 'undefined' || Boolean(await getParentPort());
|
|
19
35
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
onMessageWrapper = async message => {
|
|
33
|
-
if (!isKnownMessage(message)) {
|
|
34
|
-
return;
|
|
36
|
+
/*
|
|
37
|
+
* (type: WorkerMessageType, payload: WorkerMessagePayload) => any
|
|
38
|
+
*/
|
|
39
|
+
static set onmessage(onMessage) {
|
|
40
|
+
async function handleMessage(message) {
|
|
41
|
+
const parentPort = await getParentPort();
|
|
42
|
+
// Confusingly the message itself also has a 'type' field which is always set to 'message'
|
|
43
|
+
const { type, payload } = parentPort ? message : message.data;
|
|
44
|
+
// if (!isKnownMessage(message)) {
|
|
45
|
+
// return;
|
|
46
|
+
// }
|
|
47
|
+
onMessage(type, payload);
|
|
35
48
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
49
|
+
getParentPort().then((parentPort) => {
|
|
50
|
+
if (parentPort) {
|
|
51
|
+
parentPort.on('message', (message) => {
|
|
52
|
+
handleMessage(message);
|
|
53
|
+
});
|
|
54
|
+
// if (message == 'exit') { parentPort.unref(); }
|
|
55
|
+
// eslint-disable-next-line
|
|
56
|
+
parentPort.on('exit', () => console.debug('Node worker closing'));
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
// eslint-disable-next-line no-restricted-globals
|
|
60
|
+
globalThis.onmessage = handleMessage;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
43
63
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
64
|
+
static async addEventListener(onMessage) {
|
|
65
|
+
let onMessageWrapper = onMessageWrapperMap.get(onMessage);
|
|
66
|
+
if (!onMessageWrapper) {
|
|
67
|
+
onMessageWrapper = async (message) => {
|
|
68
|
+
if (!isKnownMessage(message)) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const parentPort = await getParentPort();
|
|
72
|
+
// Confusingly in the browser, the message itself also has a 'type' field which is always set to 'message'
|
|
73
|
+
const { type, payload } = parentPort ? message : message.data;
|
|
74
|
+
onMessage(type, payload);
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
const parentPort = await getParentPort();
|
|
78
|
+
if (parentPort) {
|
|
79
|
+
console.error('not implemented'); // eslint-disable-line
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
globalThis.addEventListener('message', onMessageWrapper);
|
|
83
|
+
}
|
|
49
84
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
85
|
+
static async removeEventListener(onMessage) {
|
|
86
|
+
const onMessageWrapper = onMessageWrapperMap.get(onMessage);
|
|
87
|
+
onMessageWrapperMap.delete(onMessage);
|
|
88
|
+
const parentPort = await getParentPort();
|
|
89
|
+
if (parentPort) {
|
|
90
|
+
console.error('not implemented'); // eslint-disable-line
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
globalThis.removeEventListener('message', onMessageWrapper);
|
|
94
|
+
}
|
|
59
95
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
96
|
+
/**
|
|
97
|
+
* Send a message from a worker to creating thread (main thread)
|
|
98
|
+
* @param type
|
|
99
|
+
* @param payload
|
|
100
|
+
*/
|
|
101
|
+
static async postMessage(type, payload) {
|
|
102
|
+
const data = { source: 'loaders.gl', type, payload };
|
|
103
|
+
// console.log('posting message', data);
|
|
104
|
+
// Cast to Node compatible transfer list
|
|
105
|
+
const transferList = getTransferList(payload);
|
|
106
|
+
const parentPort = await getParentPort();
|
|
107
|
+
if (parentPort) {
|
|
108
|
+
parentPort.postMessage(data, transferList);
|
|
109
|
+
// console.log('posted message', data);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
// @ts-expect-error Outside of worker scopes this call has a third parameter
|
|
113
|
+
globalThis.postMessage(data, transferList);
|
|
114
|
+
}
|
|
73
115
|
}
|
|
74
|
-
}
|
|
75
116
|
}
|
|
117
|
+
// Filter out noise messages sent to workers
|
|
76
118
|
function isKnownMessage(message) {
|
|
77
|
-
|
|
78
|
-
type
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
119
|
+
const { type, data } = message;
|
|
120
|
+
return (type === 'message' &&
|
|
121
|
+
data &&
|
|
122
|
+
typeof data.source === 'string' &&
|
|
123
|
+
data.source.startsWith('loaders.gl'));
|
|
82
124
|
}
|
|
83
|
-
//# sourceMappingURL=worker-body.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-farm.d.ts","sourceRoot":"","sources":["../../../src/lib/worker-farm/worker-farm.ts"],"names":[],"mappings":"AAIA,OAAO,UAAU,
|
|
1
|
+
{"version":3,"file":"worker-farm.d.ts","sourceRoot":"","sources":["../../../src/lib/worker-farm/worker-farm.ts"],"names":[],"mappings":"AAIA,OAAO,UAAU,yBAAsB;AAGvC;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB,CAAC;AASF;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,OAAO,CAAC,KAAK,CAAkB;IAC/B,OAAO,CAAC,WAAW,CAAiC;IAEpD,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,CAAa;IAExC,uDAAuD;IACvD,MAAM,CAAC,WAAW,IAAI,OAAO;IAI7B,2DAA2D;IAC3D,MAAM,CAAC,aAAa,CAAC,KAAK,GAAE,eAAoB,GAAG,UAAU;IAM7D,0DAA0D;IAC1D,OAAO;IAOP;;;OAGG;IACH,OAAO,IAAI,IAAI;IAOf;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI;IAQtC;;;;;;;;OAQG;IACH,aAAa,CAAC,OAAO,EAAE;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAC,GAAG,UAAU;IAejF,mBAAmB;;;;;;CAQpB"}
|
|
@@ -1,71 +1,89 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
import WorkerPool from "./worker-pool.js";
|
|
2
5
|
import WorkerThread from "./worker-thread.js";
|
|
3
6
|
const DEFAULT_PROPS = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
maxConcurrency: 3,
|
|
8
|
+
maxMobileConcurrency: 1,
|
|
9
|
+
reuseWorkers: true,
|
|
10
|
+
onDebug: () => { }
|
|
8
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* Process multiple jobs with a "farm" of different workers in worker pools.
|
|
14
|
+
*/
|
|
9
15
|
export default class WorkerFarm {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return WorkerFarm._workerFarm;
|
|
18
|
-
}
|
|
19
|
-
constructor(props) {
|
|
20
|
-
this.props = void 0;
|
|
21
|
-
this.workerPools = new Map();
|
|
22
|
-
this.props = {
|
|
23
|
-
...DEFAULT_PROPS
|
|
24
|
-
};
|
|
25
|
-
this.setProps(props);
|
|
26
|
-
this.workerPools = new Map();
|
|
27
|
-
}
|
|
28
|
-
destroy() {
|
|
29
|
-
for (const workerPool of this.workerPools.values()) {
|
|
30
|
-
workerPool.destroy();
|
|
16
|
+
props;
|
|
17
|
+
workerPools = new Map();
|
|
18
|
+
// singleton
|
|
19
|
+
static _workerFarm;
|
|
20
|
+
/** Checks if workers are supported on this platform */
|
|
21
|
+
static isSupported() {
|
|
22
|
+
return WorkerThread.isSupported();
|
|
31
23
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
...props
|
|
38
|
-
};
|
|
39
|
-
for (const workerPool of this.workerPools.values()) {
|
|
40
|
-
workerPool.setProps(this._getWorkerPoolProps());
|
|
24
|
+
/** Get the singleton instance of the global worker farm */
|
|
25
|
+
static getWorkerFarm(props = {}) {
|
|
26
|
+
WorkerFarm._workerFarm = WorkerFarm._workerFarm || new WorkerFarm({});
|
|
27
|
+
WorkerFarm._workerFarm.setProps(props);
|
|
28
|
+
return WorkerFarm._workerFarm;
|
|
41
29
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
30
|
+
/** get global instance with WorkerFarm.getWorkerFarm() */
|
|
31
|
+
constructor(props) {
|
|
32
|
+
this.props = { ...DEFAULT_PROPS };
|
|
33
|
+
this.setProps(props);
|
|
34
|
+
/** @type Map<string, WorkerPool>} */
|
|
35
|
+
this.workerPools = new Map();
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Terminate all workers in the farm
|
|
39
|
+
* @note Can free up significant memory
|
|
40
|
+
*/
|
|
41
|
+
destroy() {
|
|
42
|
+
for (const workerPool of this.workerPools.values()) {
|
|
43
|
+
workerPool.destroy();
|
|
44
|
+
}
|
|
45
|
+
this.workerPools = new Map();
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Set props used when initializing worker pools
|
|
49
|
+
* @param props
|
|
50
|
+
*/
|
|
51
|
+
setProps(props) {
|
|
52
|
+
this.props = { ...this.props, ...props };
|
|
53
|
+
// Update worker pool props
|
|
54
|
+
for (const workerPool of this.workerPools.values()) {
|
|
55
|
+
workerPool.setProps(this._getWorkerPoolProps());
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Returns a worker pool for the specified worker
|
|
60
|
+
* @param options - only used first time for a specific worker name
|
|
61
|
+
* @param options.name - the name of the worker - used to identify worker pool
|
|
62
|
+
* @param options.url -
|
|
63
|
+
* @param options.source -
|
|
64
|
+
* @example
|
|
65
|
+
* const job = WorkerFarm.getWorkerFarm().getWorkerPool({name, url}).startJob(...);
|
|
66
|
+
*/
|
|
67
|
+
getWorkerPool(options) {
|
|
68
|
+
const { name, source, url } = options;
|
|
69
|
+
let workerPool = this.workerPools.get(name);
|
|
70
|
+
if (!workerPool) {
|
|
71
|
+
workerPool = new WorkerPool({
|
|
72
|
+
name,
|
|
73
|
+
source,
|
|
74
|
+
url
|
|
75
|
+
});
|
|
76
|
+
workerPool.setProps(this._getWorkerPoolProps());
|
|
77
|
+
this.workerPools.set(name, workerPool);
|
|
78
|
+
}
|
|
79
|
+
return workerPool;
|
|
80
|
+
}
|
|
81
|
+
_getWorkerPoolProps() {
|
|
82
|
+
return {
|
|
83
|
+
maxConcurrency: this.props.maxConcurrency,
|
|
84
|
+
maxMobileConcurrency: this.props.maxMobileConcurrency,
|
|
85
|
+
reuseWorkers: this.props.reuseWorkers,
|
|
86
|
+
onDebug: this.props.onDebug
|
|
87
|
+
};
|
|
58
88
|
}
|
|
59
|
-
return workerPool;
|
|
60
|
-
}
|
|
61
|
-
_getWorkerPoolProps() {
|
|
62
|
-
return {
|
|
63
|
-
maxConcurrency: this.props.maxConcurrency,
|
|
64
|
-
maxMobileConcurrency: this.props.maxMobileConcurrency,
|
|
65
|
-
reuseWorkers: this.props.reuseWorkers,
|
|
66
|
-
onDebug: this.props.onDebug
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
89
|
}
|
|
70
|
-
WorkerFarm._workerFarm = void 0;
|
|
71
|
-
//# sourceMappingURL=worker-farm.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { WorkerMessageType, WorkerMessagePayload } from
|
|
2
|
-
import WorkerThread from
|
|
1
|
+
import type { WorkerMessageType, WorkerMessagePayload } from "../../types.js";
|
|
2
|
+
import WorkerThread from "./worker-thread.js";
|
|
3
3
|
/**
|
|
4
4
|
* Represents one Job handled by a WorkerPool or WorkerFarm
|
|
5
5
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-job.d.ts","sourceRoot":"","sources":["../../../src/lib/worker-farm/worker-job.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,iBAAiB,EAAE,oBAAoB,EAAC,
|
|
1
|
+
{"version":3,"file":"worker-job.d.ts","sourceRoot":"","sources":["../../../src/lib/worker-farm/worker-job.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,iBAAiB,EAAE,oBAAoB,EAAC,uBAAoB;AACzE,OAAO,YAAY,2BAAwB;AAG3C;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,SAAS;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;IACpC,SAAS,EAAE,OAAO,CAAQ;IAC1B,6CAA6C;IAC7C,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;IAE9B,OAAO,CAAC,QAAQ,CAAkC;IAClD,OAAO,CAAC,OAAO,CAAoC;gBAEvC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY;IASvD;;;OAGG;IACH,WAAW,CAAC,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,oBAAoB,GAAG,IAAI;IAQzE;;OAEG;IACH,IAAI,CAAC,KAAK,EAAE,GAAG,GAAG,IAAI;IAMtB;;OAEG;IACH,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;CAK1B"}
|
|
@@ -1,35 +1,51 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
import { assert } from "../env-utils/assert.js";
|
|
5
|
+
/**
|
|
6
|
+
* Represents one Job handled by a WorkerPool or WorkerFarm
|
|
7
|
+
*/
|
|
2
8
|
export default class WorkerJob {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
9
|
+
name;
|
|
10
|
+
workerThread;
|
|
11
|
+
isRunning = true;
|
|
12
|
+
/** Promise that resolves when Job is done */
|
|
13
|
+
result;
|
|
14
|
+
_resolve = () => { };
|
|
15
|
+
_reject = () => { };
|
|
16
|
+
constructor(jobName, workerThread) {
|
|
17
|
+
this.name = jobName;
|
|
18
|
+
this.workerThread = workerThread;
|
|
19
|
+
this.result = new Promise((resolve, reject) => {
|
|
20
|
+
this._resolve = resolve;
|
|
21
|
+
this._reject = reject;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Send a message to the job's worker thread
|
|
26
|
+
* @param data any data structure, ideally consisting mostly of transferrable objects
|
|
27
|
+
*/
|
|
28
|
+
postMessage(type, payload) {
|
|
29
|
+
this.workerThread.postMessage({
|
|
30
|
+
source: 'loaders.gl', // Lets worker ignore unrelated messages
|
|
31
|
+
type,
|
|
32
|
+
payload
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Call to resolve the `result` Promise with the supplied value
|
|
37
|
+
*/
|
|
38
|
+
done(value) {
|
|
39
|
+
assert(this.isRunning);
|
|
40
|
+
this.isRunning = false;
|
|
41
|
+
this._resolve(value);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Call to reject the `result` Promise with the supplied error
|
|
45
|
+
*/
|
|
46
|
+
error(error) {
|
|
47
|
+
assert(this.isRunning);
|
|
48
|
+
this.isRunning = false;
|
|
49
|
+
this._reject(error);
|
|
50
|
+
}
|
|
34
51
|
}
|
|
35
|
-
//# sourceMappingURL=worker-job.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { WorkerMessageType, WorkerMessagePayload } from
|
|
2
|
-
import WorkerThread from
|
|
3
|
-
import WorkerJob from
|
|
1
|
+
import type { WorkerMessageType, WorkerMessagePayload } from "../../types.js";
|
|
2
|
+
import WorkerThread from "./worker-thread.js";
|
|
3
|
+
import WorkerJob from "./worker-job.js";
|
|
4
4
|
/** WorkerPool onDebug Callback Parameters */
|
|
5
5
|
type OnDebugParameters = {
|
|
6
6
|
message: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-pool.d.ts","sourceRoot":"","sources":["../../../src/lib/worker-farm/worker-pool.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,iBAAiB,EAAE,oBAAoB,EAAC,
|
|
1
|
+
{"version":3,"file":"worker-pool.d.ts","sourceRoot":"","sources":["../../../src/lib/worker-farm/worker-pool.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,iBAAiB,EAAE,oBAAoB,EAAC,uBAAoB;AAEzE,OAAO,YAAY,2BAAwB;AAC3C,OAAO,SAAS,wBAAqB;AAErC,6CAA6C;AAC7C,KAAK,iBAAiB,GAAG;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,YAAY,CAAC;CAC5B,CAAC;AAEF,4BAA4B;AAC5B,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,GAAG,CAAC;IAC9C,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,2BAA2B;AAC3B,KAAK,SAAS,GAAG,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,oBAAoB,KAAK,IAAI,CAAC;AAClG,KAAK,OAAO,GAAG,CAAC,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;AAStD;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,IAAI,EAAE,MAAM,CAAa;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,CAAK;IAC3B,oBAAoB,EAAE,MAAM,CAAK;IACjC,OAAO,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,GAAG,CAAY;IACxD,YAAY,EAAE,OAAO,CAAQ;IAE7B,OAAO,CAAC,KAAK,CAAuB;IACpC,OAAO,CAAC,QAAQ,CAAmB;IACnC,OAAO,CAAC,SAAS,CAAsB;IACvC,OAAO,CAAC,KAAK,CAAK;IAClB,OAAO,CAAC,WAAW,CAAS;IAE5B,uDAAuD;IACvD,MAAM,CAAC,WAAW,IAAI,OAAO;IAI7B;;;OAGG;gBACS,KAAK,EAAE,eAAe;IAMlC;;;OAGG;IACH,OAAO,IAAI,IAAI;IAMf,QAAQ,CAAC,KAAK,EAAE,eAAe;IAoBzB,QAAQ,CACZ,IAAI,EAAE,MAAM,EACZ,SAAS,GAAE,SAA+C,EAC1D,OAAO,GAAE,OAA0C,GAClD,OAAO,CAAC,SAAS,CAAC;IAarB;;;OAGG;IACG,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;IA4CtC;;;;;;;OAOG;IACH,mBAAmB,CAAC,MAAM,EAAE,YAAY;IAwBxC;;OAEG;IACH,mBAAmB,IAAI,YAAY,GAAG,IAAI;IAiB1C,kBAAkB;CAGnB"}
|