@loaders.gl/core 5.0.0-beta.1 → 5.0.0-beta.4
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/README.md +3 -1
- package/dist/cluster-source.cjs +7228 -0
- package/dist/cluster-source.cjs.map +6 -0
- package/dist/cluster-source.d.ts +2 -0
- package/dist/cluster-source.d.ts.map +1 -0
- package/dist/cluster-source.js +2 -0
- package/dist/cluster-source.js.map +1 -0
- package/dist/dist.dev.js +2141 -438
- package/dist/dist.min.js +3 -3
- package/dist/federated-table-scan-source.cjs +2677 -0
- package/dist/federated-table-scan-source.cjs.map +6 -0
- package/dist/federated-table-scan-source.d.ts +2 -0
- package/dist/federated-table-scan-source.d.ts.map +1 -0
- package/dist/federated-table-scan-source.js +2 -0
- package/dist/federated-table-scan-source.js.map +1 -0
- package/dist/index.cjs +268 -960
- package/dist/index.cjs.map +3 -3
- package/dist/lib/init.js +1 -1
- package/dist/loader-utils/index.cjs +418 -1234
- package/dist/loader-utils/index.cjs.map +3 -3
- package/dist/loader-utils/json-loader.js +1 -1
- package/dist/loader-utils/lib/log-utils/log.js +1 -1
- package/dist/loader-utils/lib/worker-loader-utils/encode-with-worker.d.ts.map +1 -1
- package/dist/loader-utils/lib/worker-loader-utils/encode-with-worker.js +2 -5
- package/dist/loader-utils/lib/worker-loader-utils/encode-with-worker.js.map +1 -1
- package/dist/loader-utils/lib/worker-loader-utils/parse-with-worker.d.ts.map +1 -1
- package/dist/loader-utils/lib/worker-loader-utils/parse-with-worker.js +14 -6
- package/dist/loader-utils/lib/worker-loader-utils/parse-with-worker.js.map +1 -1
- package/dist/loader-utils/loader-types.d.ts +2 -2
- package/dist/loader-utils/loader-types.d.ts.map +1 -1
- package/dist/null-loader.js +1 -1
- package/dist/null-worker-node.js +538 -82
- package/dist/null-worker.js +514 -81
- package/dist/polyfills/images/encode-image-node.d.ts +18 -15
- package/dist/polyfills/images/encode-image-node.d.ts.map +1 -1
- package/dist/polyfills/images/encode-image-node.js +19 -33
- package/dist/polyfills/images/encode-image-node.js.map +1 -1
- package/dist/polyfills/images/image-codecs-node.d.ts +2 -6
- package/dist/polyfills/images/image-codecs-node.d.ts.map +1 -1
- package/dist/polyfills/images/image-codecs-node.js +2 -24
- package/dist/polyfills/images/image-codecs-node.js.map +1 -1
- package/dist/polyfills/images/load-sharp.d.ts +3 -0
- package/dist/polyfills/images/load-sharp.d.ts.map +1 -0
- package/dist/polyfills/images/load-sharp.js +11 -0
- package/dist/polyfills/images/load-sharp.js.map +1 -0
- package/dist/polyfills/images/node-image-bitmap.d.ts +1 -1
- package/dist/polyfills/images/node-image-bitmap.js +1 -1
- package/dist/polyfills/images/node-image-formats.d.ts +1 -1
- package/dist/polyfills/images/node-image-formats.d.ts.map +1 -1
- package/dist/polyfills/images/node-image-formats.js +10 -4
- package/dist/polyfills/images/node-image-formats.js.map +1 -1
- package/dist/polyfills/images/parse-image-node.d.ts +10 -2
- package/dist/polyfills/images/parse-image-node.d.ts.map +1 -1
- package/dist/polyfills/images/parse-image-node.js +20 -32
- package/dist/polyfills/images/parse-image-node.js.map +1 -1
- package/dist/polyfills/index.cjs +73 -149
- package/dist/vector-table-scan-source.cjs +1703 -0
- package/dist/vector-table-scan-source.cjs.map +6 -0
- package/dist/vector-table-scan-source.d.ts +2 -0
- package/dist/vector-table-scan-source.d.ts.map +1 -0
- package/dist/vector-table-scan-source.js +2 -0
- package/dist/vector-table-scan-source.js.map +1 -0
- package/dist/worker-utils/index.cjs +371 -1182
- package/dist/worker-utils/index.cjs.map +3 -3
- package/dist/worker-utils/index.d.ts +5 -8
- package/dist/worker-utils/index.d.ts.map +1 -1
- package/dist/worker-utils/index.js +4 -10
- package/dist/worker-utils/index.js.map +1 -1
- package/dist/worker-utils/lib/env-utils/version.js +1 -1
- package/dist/worker-utils/lib/worker-api/create-worker.d.ts +5 -7
- package/dist/worker-utils/lib/worker-api/create-worker.d.ts.map +1 -1
- package/dist/worker-utils/lib/worker-api/create-worker.js +76 -146
- package/dist/worker-utils/lib/worker-api/create-worker.js.map +1 -1
- package/dist/worker-utils/lib/worker-api/process-on-worker.d.ts +16 -47
- package/dist/worker-utils/lib/worker-api/process-on-worker.d.ts.map +1 -1
- package/dist/worker-utils/lib/worker-api/process-on-worker.js +214 -312
- package/dist/worker-utils/lib/worker-api/process-on-worker.js.map +1 -1
- package/dist/worker-utils/lib/worker-api/task-runtime.d.ts +36 -0
- package/dist/worker-utils/lib/worker-api/task-runtime.d.ts.map +1 -0
- package/dist/worker-utils/lib/worker-api/task-runtime.js +23 -0
- package/dist/worker-utils/lib/worker-api/task-runtime.js.map +1 -0
- package/dist/worker-utils/lib/worker-utils/get-transfer-list.d.ts +1 -0
- package/dist/worker-utils/lib/worker-utils/get-transfer-list.d.ts.map +1 -1
- package/dist/worker-utils/lib/worker-utils/get-transfer-list.js +3 -1
- package/dist/worker-utils/lib/worker-utils/get-transfer-list.js.map +1 -1
- package/dist/worker-utils/null-worker-node.js +603 -147
- package/dist/worker-utils/null-worker-node.js.map +4 -4
- package/dist/worker-utils/null-worker.js +576 -143
- package/dist/worker-utils/null-worker.js.map +4 -4
- package/dist/worker-utils/types.d.ts +55 -72
- package/dist/worker-utils/types.d.ts.map +1 -1
- package/package.json +27 -29
- package/src/cluster-source.ts +1 -0
- package/src/federated-table-scan-source.ts +1 -0
- package/src/loader-utils/lib/worker-loader-utils/encode-with-worker.ts +5 -6
- package/src/loader-utils/lib/worker-loader-utils/parse-with-worker.ts +14 -6
- package/src/loader-utils/loader-types.ts +2 -2
- package/src/polyfills/README.md +2 -2
- package/src/polyfills/images/encode-image-node.ts +44 -37
- package/src/polyfills/images/image-codecs-node.ts +2 -37
- package/src/polyfills/images/load-sharp.ts +13 -0
- package/src/polyfills/images/node-image-bitmap.ts +1 -1
- package/src/polyfills/images/node-image-formats.ts +10 -4
- package/src/polyfills/images/parse-image-node.ts +31 -40
- package/src/vector-table-scan-source.ts +1 -0
- package/src/worker-utils/index.ts +17 -17
- package/src/worker-utils/lib/worker-api/create-worker.ts +89 -188
- package/src/worker-utils/lib/worker-api/process-on-worker.ts +249 -403
- package/src/worker-utils/lib/worker-api/task-runtime.ts +66 -0
- package/src/worker-utils/lib/worker-utils/get-transfer-list.ts +2 -0
- package/src/worker-utils/types.ts +74 -109
- package/dist/worker-utils/lib/async-queue/async-queue.d.ts +0 -32
- package/dist/worker-utils/lib/async-queue/async-queue.d.ts.map +0 -1
- package/dist/worker-utils/lib/async-queue/async-queue.js +0 -91
- package/dist/worker-utils/lib/async-queue/async-queue.js.map +0 -1
- package/dist/worker-utils/lib/worker-farm/worker-body.d.ts +0 -20
- package/dist/worker-utils/lib/worker-farm/worker-body.d.ts.map +0 -1
- package/dist/worker-utils/lib/worker-farm/worker-body.js +0 -131
- package/dist/worker-utils/lib/worker-farm/worker-body.js.map +0 -1
- package/dist/worker-utils/lib/worker-farm/worker-farm.d.ts +0 -58
- package/dist/worker-utils/lib/worker-farm/worker-farm.d.ts.map +0 -1
- package/dist/worker-utils/lib/worker-farm/worker-farm.js +0 -116
- package/dist/worker-utils/lib/worker-farm/worker-farm.js.map +0 -1
- package/dist/worker-utils/lib/worker-farm/worker-job.d.ts +0 -34
- package/dist/worker-utils/lib/worker-farm/worker-job.d.ts.map +0 -1
- package/dist/worker-utils/lib/worker-farm/worker-job.js +0 -74
- package/dist/worker-utils/lib/worker-farm/worker-job.js.map +0 -1
- package/dist/worker-utils/lib/worker-farm/worker-pool.d.ts +0 -94
- package/dist/worker-utils/lib/worker-farm/worker-pool.d.ts.map +0 -1
- package/dist/worker-utils/lib/worker-farm/worker-pool.js +0 -246
- package/dist/worker-utils/lib/worker-farm/worker-pool.js.map +0 -1
- package/dist/worker-utils/lib/worker-farm/worker-thread.d.ts +0 -67
- package/dist/worker-utils/lib/worker-farm/worker-thread.d.ts.map +0 -1
- package/dist/worker-utils/lib/worker-farm/worker-thread.js +0 -175
- package/dist/worker-utils/lib/worker-farm/worker-thread.js.map +0 -1
- package/src/polyfills/images/encode-image.node.ts.disabled +0 -41
- package/src/polyfills/images/parse-image.node.ts.disabled +0 -55
- package/src/worker-utils/lib/async-queue/async-queue.ts +0 -100
- package/src/worker-utils/lib/worker-farm/worker-body.ts +0 -145
- package/src/worker-utils/lib/worker-farm/worker-farm.ts +0 -144
- package/src/worker-utils/lib/worker-farm/worker-job.ts +0 -85
- package/src/worker-utils/lib/worker-farm/worker-pool.ts +0 -316
- package/src/worker-utils/lib/worker-farm/worker-thread.ts +0 -206
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"worker-farm.d.ts","sourceRoot":"","sources":["../../../../src/worker-utils/lib/worker-farm/worker-farm.ts"],"names":[],"mappings":"AAIA,OAAO,UAAU,yBAAsB;AACvC,OAAO,KAAK,EAAC,gBAAgB,EAAC,yBAAsB;AAIpD;;;;;;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;AAcF;;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;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI;IAO/B;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI;IAQtC;;;;;;;;;OASG;IACH,aAAa,CAAC,OAAO,EAAE,gBAAgB,GAAG,UAAU;IAkBpD,mBAAmB;;;;wBAhGH,IAAI;;CAwGrB"}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
import WorkerPool from "./worker-pool.js";
|
|
5
|
-
import WorkerThread from "./worker-thread.js";
|
|
6
|
-
const DEFAULT_PROPS = {
|
|
7
|
-
maxConcurrency: 3,
|
|
8
|
-
maxMobileConcurrency: 1,
|
|
9
|
-
reuseWorkers: true,
|
|
10
|
-
onDebug: () => { }
|
|
11
|
-
};
|
|
12
|
-
/** Stable ids used to distinguish worker factories in the pool cache. */
|
|
13
|
-
const loadWorkerIds = new WeakMap();
|
|
14
|
-
/** Next stable worker-factory id. */
|
|
15
|
-
let nextLoadWorkerId = 1;
|
|
16
|
-
/**
|
|
17
|
-
* Process multiple jobs with a "farm" of different workers in worker pools.
|
|
18
|
-
*/
|
|
19
|
-
export default class WorkerFarm {
|
|
20
|
-
props;
|
|
21
|
-
workerPools = new Map();
|
|
22
|
-
// singleton
|
|
23
|
-
static _workerFarm;
|
|
24
|
-
/** Checks if workers are supported on this platform */
|
|
25
|
-
static isSupported() {
|
|
26
|
-
return WorkerThread.isSupported();
|
|
27
|
-
}
|
|
28
|
-
/** Get the singleton instance of the global worker farm */
|
|
29
|
-
static getWorkerFarm(props = {}) {
|
|
30
|
-
WorkerFarm._workerFarm = WorkerFarm._workerFarm || new WorkerFarm({});
|
|
31
|
-
WorkerFarm._workerFarm.setProps(props);
|
|
32
|
-
return WorkerFarm._workerFarm;
|
|
33
|
-
}
|
|
34
|
-
/** get global instance with WorkerFarm.getWorkerFarm() */
|
|
35
|
-
constructor(props) {
|
|
36
|
-
this.props = { ...DEFAULT_PROPS };
|
|
37
|
-
this.setProps(props);
|
|
38
|
-
/** @type Map<string, WorkerPool>} */
|
|
39
|
-
this.workerPools = new Map();
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Terminate all workers in the farm and abort active jobs.
|
|
43
|
-
* @param reason Optional error delivered to active jobs.
|
|
44
|
-
* @note Can free up significant memory
|
|
45
|
-
*/
|
|
46
|
-
destroy(reason) {
|
|
47
|
-
for (const workerPool of this.workerPools.values()) {
|
|
48
|
-
workerPool.destroy(reason);
|
|
49
|
-
}
|
|
50
|
-
this.workerPools = new Map();
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Set props used when initializing worker pools
|
|
54
|
-
* @param props
|
|
55
|
-
*/
|
|
56
|
-
setProps(props) {
|
|
57
|
-
this.props = { ...this.props, ...props };
|
|
58
|
-
// Update worker pool props
|
|
59
|
-
for (const workerPool of this.workerPools.values()) {
|
|
60
|
-
workerPool.setProps(this._getWorkerPoolProps());
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Returns a worker pool for the specified worker
|
|
65
|
-
* @param options Worker target used to identify and initialize the pool.
|
|
66
|
-
* @param options.name Worker name used as the base pool identity.
|
|
67
|
-
* @param options.url Worker script URL.
|
|
68
|
-
* @param options.source Inline worker source.
|
|
69
|
-
* @param options.loadWorker Built-in browser worker factory.
|
|
70
|
-
* @example
|
|
71
|
-
* const job = WorkerFarm.getWorkerFarm().getWorkerPool({name, url}).startJob(...);
|
|
72
|
-
*/
|
|
73
|
-
getWorkerPool(options) {
|
|
74
|
-
const { name, source, url, getUrl, loadWorker } = options;
|
|
75
|
-
const workerPoolKey = getWorkerPoolKey(options);
|
|
76
|
-
let workerPool = this.workerPools.get(workerPoolKey);
|
|
77
|
-
if (!workerPool) {
|
|
78
|
-
workerPool = new WorkerPool({
|
|
79
|
-
name,
|
|
80
|
-
source,
|
|
81
|
-
url,
|
|
82
|
-
getUrl,
|
|
83
|
-
loadWorker
|
|
84
|
-
});
|
|
85
|
-
workerPool.setProps(this._getWorkerPoolProps());
|
|
86
|
-
this.workerPools.set(workerPoolKey, workerPool);
|
|
87
|
-
}
|
|
88
|
-
return workerPool;
|
|
89
|
-
}
|
|
90
|
-
_getWorkerPoolProps() {
|
|
91
|
-
return {
|
|
92
|
-
maxConcurrency: this.props.maxConcurrency,
|
|
93
|
-
maxMobileConcurrency: this.props.maxMobileConcurrency,
|
|
94
|
-
reuseWorkers: this.props.reuseWorkers,
|
|
95
|
-
onDebug: this.props.onDebug
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
/** Returns a cache key that distinguishes each worker source and factory. */
|
|
100
|
-
function getWorkerPoolKey(options) {
|
|
101
|
-
const { name, source, url, urlKey, loadWorker } = options;
|
|
102
|
-
const sourceKey = source ? `source:${source}` : '';
|
|
103
|
-
const urlKeyPart = url || urlKey ? `url:${url || urlKey}` : '';
|
|
104
|
-
const loadWorkerKey = loadWorker ? `loadWorker:${getLoadWorkerId(loadWorker)}` : '';
|
|
105
|
-
return [name, sourceKey, urlKeyPart, loadWorkerKey].filter(Boolean).join('|');
|
|
106
|
-
}
|
|
107
|
-
/** Returns a stable identifier for a worker factory function. */
|
|
108
|
-
function getLoadWorkerId(loadWorker) {
|
|
109
|
-
let loadWorkerId = loadWorkerIds.get(loadWorker);
|
|
110
|
-
if (!loadWorkerId) {
|
|
111
|
-
loadWorkerId = nextLoadWorkerId++;
|
|
112
|
-
loadWorkerIds.set(loadWorker, loadWorkerId);
|
|
113
|
-
}
|
|
114
|
-
return loadWorkerId;
|
|
115
|
-
}
|
|
116
|
-
//# sourceMappingURL=worker-farm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"worker-farm.js","sourceRoot":"","sources":["../../../../src/worker-utils/lib/worker-farm/worker-farm.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,+BAA+B;AAC/B,oCAAoC;AAEpC,OAAO,UAAU,yBAAsB;AAEvC,OAAO,YAAY,2BAAwB;AAiB3C,MAAM,aAAa,GAA8B;IAC/C,cAAc,EAAE,CAAC;IACjB,oBAAoB,EAAE,CAAC;IACvB,YAAY,E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C,GAAG,OAAO,CAAC;IACxD,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,UAAU,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACnD,MAAM,UAAU,GAAG,GAAG,IAAI,MAAM,CAAC,CAAC,CAAC,OAAO,GAAG,IAAI,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAC/D,MAAM,aAAa,GAAG,UAAU,CAAC,CAAC,CAAC,cAAc,eAAe,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACpF,OAAO,CAAC,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAChF,CAAC;AAED,iEAAiE;AACjE,SAAS,eAAe,CAAC,UAAsB;IAC7C,IAAI,YAAY,GAAG,aAAa,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACjD,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,YAAY,GAAG,gBAAgB,EAAE,CAAC;QAClC,aAAa,CAAC,GAAG,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;IAC9C,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC"}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { WorkerMessageType, WorkerMessagePayload } from "../../types.js";
|
|
2
|
-
import WorkerThread from "./worker-thread.js";
|
|
3
|
-
/**
|
|
4
|
-
* Represents one Job handled by a WorkerPool or WorkerFarm
|
|
5
|
-
*/
|
|
6
|
-
export default class WorkerJob {
|
|
7
|
-
readonly name: string;
|
|
8
|
-
readonly workerThread: WorkerThread;
|
|
9
|
-
isRunning: boolean;
|
|
10
|
-
/** Promise that resolves when Job is done */
|
|
11
|
-
readonly result: Promise<any>;
|
|
12
|
-
private _resolve;
|
|
13
|
-
private _reject;
|
|
14
|
-
constructor(jobName: string, workerThread: WorkerThread);
|
|
15
|
-
/**
|
|
16
|
-
* Send a message to the job's worker thread
|
|
17
|
-
* @param data any data structure, ideally consisting mostly of transferrable objects
|
|
18
|
-
*/
|
|
19
|
-
postMessage(type: WorkerMessageType, payload: WorkerMessagePayload): void;
|
|
20
|
-
/**
|
|
21
|
-
* Call to resolve the `result` Promise with the supplied value
|
|
22
|
-
*/
|
|
23
|
-
done(value: any): void;
|
|
24
|
-
/**
|
|
25
|
-
* Call to reject the `result` Promise with the supplied error
|
|
26
|
-
*/
|
|
27
|
-
error(error: unknown): void;
|
|
28
|
-
/**
|
|
29
|
-
* Terminates the worker executing this job and rejects its result.
|
|
30
|
-
* @param reason Abort reason supplied by the caller, or a cross-runtime `AbortError`.
|
|
31
|
-
*/
|
|
32
|
-
abort(reason?: unknown): void;
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=worker-job.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"worker-job.d.ts","sourceRoot":"","sources":["../../../../src/worker-utils/lib/worker-farm/worker-job.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,iBAAiB,EAAE,oBAAoB,EAAC,uBAAoB;AACzE,OAAO,YAAY,2BAAwB;AAE3C;;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;IASzE;;OAEG;IACH,IAAI,CAAC,KAAK,EAAE,GAAG,GAAG,IAAI;IAQtB;;OAEG;IACH,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI;IAQ3B;;;OAGG;IACH,KAAK,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI;CAS9B"}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
/**
|
|
5
|
-
* Represents one Job handled by a WorkerPool or WorkerFarm
|
|
6
|
-
*/
|
|
7
|
-
export default class WorkerJob {
|
|
8
|
-
name;
|
|
9
|
-
workerThread;
|
|
10
|
-
isRunning = true;
|
|
11
|
-
/** Promise that resolves when Job is done */
|
|
12
|
-
result;
|
|
13
|
-
_resolve = () => { };
|
|
14
|
-
_reject = () => { };
|
|
15
|
-
constructor(jobName, workerThread) {
|
|
16
|
-
this.name = jobName;
|
|
17
|
-
this.workerThread = workerThread;
|
|
18
|
-
this.result = new Promise((resolve, reject) => {
|
|
19
|
-
this._resolve = resolve;
|
|
20
|
-
this._reject = reject;
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Send a message to the job's worker thread
|
|
25
|
-
* @param data any data structure, ideally consisting mostly of transferrable objects
|
|
26
|
-
*/
|
|
27
|
-
postMessage(type, payload) {
|
|
28
|
-
if (!this.isRunning)
|
|
29
|
-
return;
|
|
30
|
-
this.workerThread.postMessage({
|
|
31
|
-
source: 'loaders.gl', // Lets worker ignore unrelated messages
|
|
32
|
-
type,
|
|
33
|
-
payload
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Call to resolve the `result` Promise with the supplied value
|
|
38
|
-
*/
|
|
39
|
-
done(value) {
|
|
40
|
-
if (!this.isRunning) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
this.isRunning = false;
|
|
44
|
-
this._resolve(value);
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Call to reject the `result` Promise with the supplied error
|
|
48
|
-
*/
|
|
49
|
-
error(error) {
|
|
50
|
-
if (!this.isRunning) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
this.isRunning = false;
|
|
54
|
-
this._reject(error);
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Terminates the worker executing this job and rejects its result.
|
|
58
|
-
* @param reason Abort reason supplied by the caller, or a cross-runtime `AbortError`.
|
|
59
|
-
*/
|
|
60
|
-
abort(reason) {
|
|
61
|
-
if (!this.isRunning) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
this.workerThread.destroy();
|
|
65
|
-
this.error(arguments.length ? reason : createAbortError(`Worker job "${this.name}" was aborted`));
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
/** Creates an abort error without requiring the DOMException global. */
|
|
69
|
-
function createAbortError(message) {
|
|
70
|
-
const error = new Error(message);
|
|
71
|
-
error.name = 'AbortError';
|
|
72
|
-
return error;
|
|
73
|
-
}
|
|
74
|
-
//# sourceMappingURL=worker-job.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"worker-job.js","sourceRoot":"","sources":["../../../../src/worker-utils/lib/worker-farm/worker-job.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,+BAA+B;AAC/B,oCAAoC;AAKpC;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,SAAS;IACnB,IAAI,CAAS;IACb,YAAY,CAAe;IACpC,SAAS,GAAY,IAAI,CAAC;IAC1B,6CAA6C;IACpC,MAAM,CAAe;IAEtB,QAAQ,GAAyB,GAAG,EAAE,GAAE,CAAC,CAAC;IAC1C,OAAO,GAA2B,GAAG,EAAE,GAAE,CAAC,CAAC;IAEnD,YAAY,OAAe,EAAE,YAA0B;QACrD,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;QACpB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,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AAK,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;IACjC,KAAK,CAAC,IAAI,GAAG,YAAY,CAAC;IAC1B,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import type { LoadWorker, WorkerMessageType, WorkerMessagePayload } from "../../types.js";
|
|
2
|
-
import WorkerThread from "./worker-thread.js";
|
|
3
|
-
import WorkerJob from "./worker-job.js";
|
|
4
|
-
/** WorkerPool onDebug Callback Parameters */
|
|
5
|
-
type OnDebugParameters = {
|
|
6
|
-
message: string;
|
|
7
|
-
worker: string;
|
|
8
|
-
name: string;
|
|
9
|
-
job: string;
|
|
10
|
-
backlog: number;
|
|
11
|
-
workerThread: WorkerThread;
|
|
12
|
-
};
|
|
13
|
-
/** WorkerPool Properties */
|
|
14
|
-
export type WorkerPoolProps = {
|
|
15
|
-
name?: string;
|
|
16
|
-
source?: string;
|
|
17
|
-
url?: string;
|
|
18
|
-
/** Lazily resolves a classic worker fallback URL. */
|
|
19
|
-
getUrl?: () => string;
|
|
20
|
-
/** Creates a browser Worker directly. */
|
|
21
|
-
loadWorker?: LoadWorker;
|
|
22
|
-
maxConcurrency?: number;
|
|
23
|
-
maxMobileConcurrency?: number;
|
|
24
|
-
onDebug?: (options: OnDebugParameters) => any;
|
|
25
|
-
reuseWorkers?: boolean;
|
|
26
|
-
};
|
|
27
|
-
/** Worker-pool target, including values used only to distinguish cached pools. */
|
|
28
|
-
export type WorkerPoolTarget = WorkerPoolProps & {
|
|
29
|
-
/** Worker name used as the base pool identity. */
|
|
30
|
-
name: string;
|
|
31
|
-
/** Stable identity for a lazily resolved URL. */
|
|
32
|
-
urlKey?: string;
|
|
33
|
-
};
|
|
34
|
-
/** Private helper types */
|
|
35
|
-
type OnMessage = (job: WorkerJob, type: WorkerMessageType, payload: WorkerMessagePayload) => void;
|
|
36
|
-
type OnError = (job: WorkerJob, error: Error) => void;
|
|
37
|
-
/**
|
|
38
|
-
* Process multiple data messages with small pool of identical workers
|
|
39
|
-
*/
|
|
40
|
-
export default class WorkerPool {
|
|
41
|
-
name: string;
|
|
42
|
-
source?: string;
|
|
43
|
-
url?: string;
|
|
44
|
-
/** Lazily resolves a classic worker fallback URL. */
|
|
45
|
-
getUrl?: () => string;
|
|
46
|
-
/** Creates a browser Worker directly. */
|
|
47
|
-
loadWorker?: LoadWorker;
|
|
48
|
-
maxConcurrency: number;
|
|
49
|
-
maxMobileConcurrency: number;
|
|
50
|
-
onDebug: (options: OnDebugParameters) => any;
|
|
51
|
-
reuseWorkers: boolean;
|
|
52
|
-
private props;
|
|
53
|
-
private jobQueue;
|
|
54
|
-
private idleQueue;
|
|
55
|
-
private activeJobs;
|
|
56
|
-
private count;
|
|
57
|
-
private isDestroyed;
|
|
58
|
-
/** Checks if workers are supported on this platform */
|
|
59
|
-
static isSupported(): boolean;
|
|
60
|
-
/**
|
|
61
|
-
* @param processor - worker function
|
|
62
|
-
* @param maxConcurrency - max count of workers
|
|
63
|
-
*/
|
|
64
|
-
constructor(props: WorkerPoolProps);
|
|
65
|
-
/**
|
|
66
|
-
* Terminates all workers in the pool and aborts active jobs.
|
|
67
|
-
* @param reason Optional error delivered to active jobs.
|
|
68
|
-
* @note Can free up significant memory
|
|
69
|
-
*/
|
|
70
|
-
destroy(reason?: unknown): void;
|
|
71
|
-
setProps(props: WorkerPoolProps): void;
|
|
72
|
-
startJob(name: string, onMessage?: OnMessage, onError?: OnError, signal?: AbortSignal): Promise<WorkerJob>;
|
|
73
|
-
/**
|
|
74
|
-
* Starts first queued job if worker is available or can be created
|
|
75
|
-
* Called when job is started and whenever a worker returns to the idleQueue
|
|
76
|
-
*/
|
|
77
|
-
_startQueuedJob(): Promise<void>;
|
|
78
|
-
/**
|
|
79
|
-
* Returns a worker to the idle queue
|
|
80
|
-
* Destroys the worker if
|
|
81
|
-
* - pool is destroyed
|
|
82
|
-
* - if this pool doesn't reuse workers
|
|
83
|
-
* - if maxConcurrency has been lowered
|
|
84
|
-
* @param worker
|
|
85
|
-
*/
|
|
86
|
-
returnWorkerToQueue(worker: WorkerThread): void;
|
|
87
|
-
/**
|
|
88
|
-
* Returns idle worker or creates new worker if maxConcurrency has not been reached
|
|
89
|
-
*/
|
|
90
|
-
_getAvailableWorker(): WorkerThread | null;
|
|
91
|
-
_getMaxConcurrency(): number;
|
|
92
|
-
}
|
|
93
|
-
export {};
|
|
94
|
-
//# sourceMappingURL=worker-pool.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"worker-pool.d.ts","sourceRoot":"","sources":["../../../../src/worker-utils/lib/worker-farm/worker-pool.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,UAAU,EAAE,iBAAiB,EAAE,oBAAoB,EAAC,uBAAoB;AAErF,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,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,MAAM,CAAC;IACtB,yCAAyC;IACzC,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,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;AAE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AS,GAAE,SAA+C,EAC1D,OAAO,GAAE,OAA0C,EACnD,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,SAAS,CAAC;IAqCrB;;;OAGG;IACG,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;IAiEtC;;;;;;;OAOG;IACH,mBAAmB,CAAC,MAAM,EAAE,YAAY;IA0BxC;;OAEG;IACH,mBAAmB,IAAI,YAAY,GAAG,IAAI;IA4B1C,kBAAkB;CAGnB"}
|
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
import { isMobile } from "../env-utils/globals.js";
|
|
5
|
-
import WorkerThread from "./worker-thread.js";
|
|
6
|
-
import WorkerJob from "./worker-job.js";
|
|
7
|
-
/**
|
|
8
|
-
* Process multiple data messages with small pool of identical workers
|
|
9
|
-
*/
|
|
10
|
-
export default class WorkerPool {
|
|
11
|
-
name = 'unnamed';
|
|
12
|
-
source; // | Function;
|
|
13
|
-
url;
|
|
14
|
-
/** Lazily resolves a classic worker fallback URL. */
|
|
15
|
-
getUrl;
|
|
16
|
-
/** Creates a browser Worker directly. */
|
|
17
|
-
loadWorker;
|
|
18
|
-
maxConcurrency = 1;
|
|
19
|
-
maxMobileConcurrency = 1;
|
|
20
|
-
onDebug = () => { };
|
|
21
|
-
reuseWorkers = true;
|
|
22
|
-
props = {};
|
|
23
|
-
jobQueue = [];
|
|
24
|
-
idleQueue = [];
|
|
25
|
-
activeJobs = new Set();
|
|
26
|
-
count = 0;
|
|
27
|
-
isDestroyed = false;
|
|
28
|
-
/** Checks if workers are supported on this platform */
|
|
29
|
-
static isSupported() {
|
|
30
|
-
return WorkerThread.isSupported();
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* @param processor - worker function
|
|
34
|
-
* @param maxConcurrency - max count of workers
|
|
35
|
-
*/
|
|
36
|
-
constructor(props) {
|
|
37
|
-
this.source = props.source;
|
|
38
|
-
this.url = props.url;
|
|
39
|
-
this.getUrl = props.getUrl;
|
|
40
|
-
this.loadWorker = props.loadWorker;
|
|
41
|
-
this.setProps(props);
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Terminates all workers in the pool and aborts active jobs.
|
|
45
|
-
* @param reason Optional error delivered to active jobs.
|
|
46
|
-
* @note Can free up significant memory
|
|
47
|
-
*/
|
|
48
|
-
destroy(reason = new Error('Worker pool was destroyed')) {
|
|
49
|
-
// Abort active jobs so callers receive an error when a development worker is invalidated.
|
|
50
|
-
this.isDestroyed = true;
|
|
51
|
-
this.activeJobs.forEach(job => job.abort(reason));
|
|
52
|
-
const queuedJobs = this.jobQueue.splice(0);
|
|
53
|
-
queuedJobs.forEach(queuedJob => {
|
|
54
|
-
queuedJob.removeAbortListener();
|
|
55
|
-
queuedJob.onReject(reason);
|
|
56
|
-
});
|
|
57
|
-
this.idleQueue.forEach(worker => worker.destroy());
|
|
58
|
-
this.isDestroyed = true;
|
|
59
|
-
}
|
|
60
|
-
setProps(props) {
|
|
61
|
-
this.props = { ...this.props, ...props };
|
|
62
|
-
if (props.name !== undefined) {
|
|
63
|
-
this.name = props.name;
|
|
64
|
-
}
|
|
65
|
-
if (props.maxConcurrency !== undefined) {
|
|
66
|
-
this.maxConcurrency = props.maxConcurrency;
|
|
67
|
-
}
|
|
68
|
-
if (props.maxMobileConcurrency !== undefined) {
|
|
69
|
-
this.maxMobileConcurrency = props.maxMobileConcurrency;
|
|
70
|
-
}
|
|
71
|
-
if (props.reuseWorkers !== undefined) {
|
|
72
|
-
this.reuseWorkers = props.reuseWorkers;
|
|
73
|
-
}
|
|
74
|
-
if (props.onDebug !== undefined) {
|
|
75
|
-
this.onDebug = props.onDebug;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
async startJob(name, onMessage = (job, type, data) => job.done(data), onError = (job, error) => job.error(error), signal) {
|
|
79
|
-
if (signal?.aborted) {
|
|
80
|
-
throw signal.reason;
|
|
81
|
-
}
|
|
82
|
-
if (this.isDestroyed) {
|
|
83
|
-
return Promise.reject(new Error('Worker pool was destroyed'));
|
|
84
|
-
}
|
|
85
|
-
// Promise resolves when thread starts working on this job
|
|
86
|
-
const startPromise = new Promise((onStart, onReject) => {
|
|
87
|
-
// Promise resolves when thread completes or fails working on this job
|
|
88
|
-
const abortQueuedJob = () => {
|
|
89
|
-
const index = this.jobQueue.indexOf(queuedJob);
|
|
90
|
-
if (index >= 0) {
|
|
91
|
-
this.jobQueue.splice(index, 1);
|
|
92
|
-
queuedJob.removeAbortListener();
|
|
93
|
-
onReject(signal?.reason);
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
const queuedJob = {
|
|
97
|
-
name,
|
|
98
|
-
onMessage,
|
|
99
|
-
onError,
|
|
100
|
-
onStart,
|
|
101
|
-
onReject,
|
|
102
|
-
signal,
|
|
103
|
-
removeAbortListener: () => signal?.removeEventListener('abort', abortQueuedJob)
|
|
104
|
-
};
|
|
105
|
-
this.jobQueue.push(queuedJob);
|
|
106
|
-
signal?.addEventListener('abort', abortQueuedJob, { once: true });
|
|
107
|
-
return this;
|
|
108
|
-
});
|
|
109
|
-
this._startQueuedJob(); // eslint-disable-line @typescript-eslint/no-floating-promises
|
|
110
|
-
return await startPromise;
|
|
111
|
-
}
|
|
112
|
-
// PRIVATE
|
|
113
|
-
/**
|
|
114
|
-
* Starts first queued job if worker is available or can be created
|
|
115
|
-
* Called when job is started and whenever a worker returns to the idleQueue
|
|
116
|
-
*/
|
|
117
|
-
async _startQueuedJob() {
|
|
118
|
-
if (!this.jobQueue.length) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
let workerThread;
|
|
122
|
-
try {
|
|
123
|
-
workerThread = this._getAvailableWorker();
|
|
124
|
-
}
|
|
125
|
-
catch (error) {
|
|
126
|
-
const queuedJob = this.jobQueue.shift();
|
|
127
|
-
queuedJob?.removeAbortListener();
|
|
128
|
-
queuedJob?.onReject(error);
|
|
129
|
-
void this._startQueuedJob();
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
if (!workerThread) {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
// We have a worker, dequeue and start the job
|
|
136
|
-
const queuedJob = this.jobQueue.shift();
|
|
137
|
-
if (queuedJob) {
|
|
138
|
-
// Emit a debug event
|
|
139
|
-
// @ts-ignore
|
|
140
|
-
this.onDebug({
|
|
141
|
-
message: 'Starting job',
|
|
142
|
-
name: queuedJob.name,
|
|
143
|
-
workerThread,
|
|
144
|
-
backlog: this.jobQueue.length
|
|
145
|
-
});
|
|
146
|
-
// Create a worker job to let the app access thread and manage job completion
|
|
147
|
-
const job = new WorkerJob(queuedJob.name, workerThread);
|
|
148
|
-
queuedJob.removeAbortListener();
|
|
149
|
-
const abortJob = () => job.abort(queuedJob.signal?.reason);
|
|
150
|
-
queuedJob.signal?.addEventListener('abort', abortJob, { once: true });
|
|
151
|
-
if (queuedJob.signal?.aborted)
|
|
152
|
-
abortJob();
|
|
153
|
-
this.activeJobs.add(job);
|
|
154
|
-
workerThread.ref();
|
|
155
|
-
// Set the worker thread's message handlers
|
|
156
|
-
workerThread.onMessage = data => {
|
|
157
|
-
if (job.isRunning)
|
|
158
|
-
queuedJob.onMessage(job, data.type, data.payload);
|
|
159
|
-
};
|
|
160
|
-
workerThread.onError = error => queuedJob.onError(job, error);
|
|
161
|
-
// Resolve the start promise so that the app can start sending messages to worker
|
|
162
|
-
queuedJob.onStart(job);
|
|
163
|
-
// Wait for the app to signal that the job is complete, then return worker to queue
|
|
164
|
-
try {
|
|
165
|
-
await job.result;
|
|
166
|
-
}
|
|
167
|
-
catch {
|
|
168
|
-
// The job result promise carries worker errors back to the caller; do not duplicate-log
|
|
169
|
-
// handled rejections here.
|
|
170
|
-
}
|
|
171
|
-
finally {
|
|
172
|
-
queuedJob.signal?.removeEventListener('abort', abortJob);
|
|
173
|
-
this.activeJobs.delete(job);
|
|
174
|
-
this.returnWorkerToQueue(workerThread);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
this.returnWorkerToQueue(workerThread);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Returns a worker to the idle queue
|
|
183
|
-
* Destroys the worker if
|
|
184
|
-
* - pool is destroyed
|
|
185
|
-
* - if this pool doesn't reuse workers
|
|
186
|
-
* - if maxConcurrency has been lowered
|
|
187
|
-
* @param worker
|
|
188
|
-
*/
|
|
189
|
-
returnWorkerToQueue(worker) {
|
|
190
|
-
const shouldDestroyWorker =
|
|
191
|
-
// Aborted jobs terminate their worker immediately.
|
|
192
|
-
worker.terminated ||
|
|
193
|
-
// If the pool is destroyed, there is no reason to keep the worker around
|
|
194
|
-
this.isDestroyed ||
|
|
195
|
-
// If the app has disabled worker reuse, any completed workers should be destroyed
|
|
196
|
-
!this.reuseWorkers ||
|
|
197
|
-
// If concurrency has been lowered, this worker might be surplus to requirements
|
|
198
|
-
this.count > this._getMaxConcurrency();
|
|
199
|
-
if (shouldDestroyWorker) {
|
|
200
|
-
if (!worker.terminated) {
|
|
201
|
-
worker.destroy();
|
|
202
|
-
}
|
|
203
|
-
this.count--;
|
|
204
|
-
}
|
|
205
|
-
else {
|
|
206
|
-
worker.unref();
|
|
207
|
-
this.idleQueue.push(worker);
|
|
208
|
-
}
|
|
209
|
-
if (!this.isDestroyed) {
|
|
210
|
-
this._startQueuedJob(); // eslint-disable-line @typescript-eslint/no-floating-promises
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Returns idle worker or creates new worker if maxConcurrency has not been reached
|
|
215
|
-
*/
|
|
216
|
-
_getAvailableWorker() {
|
|
217
|
-
// If a worker has completed and returned to the queue, it can be used
|
|
218
|
-
if (this.idleQueue.length > 0) {
|
|
219
|
-
return this.idleQueue.shift() || null;
|
|
220
|
-
}
|
|
221
|
-
// Create fresh worker if we haven't yet created the max amount of worker threads for this worker source
|
|
222
|
-
if (this.count < this._getMaxConcurrency()) {
|
|
223
|
-
this.count++;
|
|
224
|
-
const name = `${this.name.toLowerCase()} (#${this.count} of ${this.maxConcurrency})`;
|
|
225
|
-
try {
|
|
226
|
-
return new WorkerThread({
|
|
227
|
-
name,
|
|
228
|
-
source: this.source,
|
|
229
|
-
url: this.url,
|
|
230
|
-
getUrl: this.getUrl,
|
|
231
|
-
loadWorker: this.loadWorker
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
catch (error) {
|
|
235
|
-
this.count--;
|
|
236
|
-
throw error;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
// No worker available, have to wait
|
|
240
|
-
return null;
|
|
241
|
-
}
|
|
242
|
-
_getMaxConcurrency() {
|
|
243
|
-
return isMobile ? this.maxMobileConcurrency : this.maxConcurrency;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
//# sourceMappingURL=worker-pool.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"worker-pool.js","sourceRoot":"","sources":["../../../../src/worker-utils/lib/worker-farm/worker-pool.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,+BAA+B;AAC/B,oCAAoC;AAGpC,OAAO,EAAC,QAAQ,EAAC,gCAA6B;AAC9C,OAAO,YAAY,2BAAwB;AAC3C,OAAO,SAAS,wBAAqB;AAmDrC;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,IAAI,GAAW,SAAS,CAAC;IACzB,MAAM,CAAU,CAAC,cAAc;IAC/B,GAAG,CAAU;IACb,qDAAqD;IACrD,MAAM,CAAgB;IACtB,yCAAyC;IACzC,UAAU,CAAc;IACxB,cAAc,GAAW,CAAC,CAAC;IAC3B,oBAAoB,GAAW,CAAC,CAAC;IACjC,OAAO,GAAwC,GAAG,EAAE,GAAE,CAAC,CAAC;IACxD,YAAY,GAAY,IAAI,CAAC;IAErB,KAAK,GAAoB,EAAE,CAAC;IAC5B,QAAQ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AED,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACtB,IAAI,CAAC,eAAe,EAAE,CAAC,CAAC,8DAA8D;QACxF,CAAC;IACH,CAAC;IAED;;OAEG;IACH,mBAAmB;QACjB,sEAAsE;QACtE,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC9B,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,IAAI,CAAC;QACxC,CAAC;QAED,wGAAwG;QACxG,IAAI,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,kBAAkB,EAAE,EAAE,CAAC;YAC3C,IAAI,CAAC,KAAK,EAAE,CAAC;YACb,MAAM,IAAI,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,MAAM,IAAI,CAAC,KAAK,OAAO,IAAI,CAAC,cAAc,GAAG,CAAC;YACrF,IAAI,CAAC;gBACH,OAAO,IAAI,YAAY,CAAC;oBACtB,IAAI;oBACJ,MAAM,EAAE,IAAI,CAAC,MAAM;oBACnB,GAAG,EAAE,IAAI,CAAC,GAAG;oBACb,MAAM,EAAE,IAAI,CAAC,MAAM;oBACnB,UAAU,EAAE,IAAI,CAAC,UAAU;iBAC5B,CAAC,CAAC;YACL,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,CAAC,KAAK,EAAE,CAAC;gBACb,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;QAED,oCAAoC;QACpC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,kBAAkB;QAChB,OAAO,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC;IACpE,CAAC;CACF"}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import type { LoadWorker } from "../../types.js";
|
|
2
|
-
import { NodeWorkerType } from "../node/worker_threads.js";
|
|
3
|
-
export type WorkerThreadProps = {
|
|
4
|
-
/** Human-readable worker name. */
|
|
5
|
-
name: string;
|
|
6
|
-
/** Inline worker source. */
|
|
7
|
-
source?: string;
|
|
8
|
-
/** Worker script URL. */
|
|
9
|
-
url?: string;
|
|
10
|
-
/** Lazily resolves the classic worker URL used as a fallback. */
|
|
11
|
-
getUrl?: () => string;
|
|
12
|
-
/** Creates a browser Worker directly. */
|
|
13
|
-
loadWorker?: LoadWorker;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Represents one worker thread
|
|
17
|
-
*/
|
|
18
|
-
export default class WorkerThread {
|
|
19
|
-
readonly name: string;
|
|
20
|
-
readonly source: string | undefined;
|
|
21
|
-
readonly url: string | undefined;
|
|
22
|
-
/** Lazily resolves the classic worker URL used as a fallback. */
|
|
23
|
-
readonly getUrl: (() => string) | undefined;
|
|
24
|
-
/** Creates a browser Worker directly. */
|
|
25
|
-
readonly loadWorker: LoadWorker | undefined;
|
|
26
|
-
terminated: boolean;
|
|
27
|
-
worker: Worker | NodeWorkerType;
|
|
28
|
-
onMessage: (message: any) => void;
|
|
29
|
-
onError: (error: Error) => void;
|
|
30
|
-
private _loadableURL;
|
|
31
|
-
/** Checks if workers are supported on this platform */
|
|
32
|
-
static isSupported(): boolean;
|
|
33
|
-
constructor(props: WorkerThreadProps);
|
|
34
|
-
/**
|
|
35
|
-
* Terminate this worker thread
|
|
36
|
-
* @note Can free up significant memory
|
|
37
|
-
*/
|
|
38
|
-
destroy(): void;
|
|
39
|
-
/** Keeps this worker from preventing Node.js process exit while idle. */
|
|
40
|
-
unref(): void;
|
|
41
|
-
/** Keeps this worker alive while it is actively processing a job. */
|
|
42
|
-
ref(): void;
|
|
43
|
-
get isRunning(): boolean;
|
|
44
|
-
/**
|
|
45
|
-
* Send a message to this worker thread
|
|
46
|
-
* @param data any data structure, ideally consisting mostly of transferrable objects
|
|
47
|
-
* @param transferList If not supplied, calculated automatically by traversing data
|
|
48
|
-
*/
|
|
49
|
-
postMessage(data: any, transferList?: any[]): void;
|
|
50
|
-
/**
|
|
51
|
-
* Generate a standard Error from an ErrorEvent
|
|
52
|
-
* @param event
|
|
53
|
-
*/
|
|
54
|
-
_getErrorFromErrorEvent(event: ErrorEvent): Error;
|
|
55
|
-
/**
|
|
56
|
-
* Creates a worker thread on the browser
|
|
57
|
-
*/
|
|
58
|
-
_createBrowserWorker(): Worker;
|
|
59
|
-
/** Attaches protocol handlers to a browser worker. */
|
|
60
|
-
_initializeBrowserWorker(worker: Worker): Worker;
|
|
61
|
-
/**
|
|
62
|
-
* Creates a worker thread in node.js
|
|
63
|
-
* @todo https://nodejs.org/api/async_hooks.html#async-resource-worker-pool
|
|
64
|
-
*/
|
|
65
|
-
_createNodeWorker(): NodeWorkerType;
|
|
66
|
-
}
|
|
67
|
-
//# sourceMappingURL=worker-thread.d.ts.map
|