@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
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
initializeTaskWorker as initializeMathTaskWorker,
|
|
7
|
+
type Task,
|
|
8
|
+
type TaskContext
|
|
9
|
+
} from '@math.gl/core/tasks';
|
|
10
|
+
import type {WorkerJobContext, WorkerProgress} from '../../types';
|
|
11
|
+
|
|
12
|
+
/** Named wire payload; TaskRunner requires plain object boundaries. */
|
|
13
|
+
export type WorkerTaskPayload = {
|
|
14
|
+
/** Loader input or decoded output. */
|
|
15
|
+
value: any;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/** State pinned to one initialized task handle. */
|
|
19
|
+
export type WorkerTaskState = {
|
|
20
|
+
/** Serializable loader context. */
|
|
21
|
+
context: WorkerJobContext;
|
|
22
|
+
/** Optional calling-thread request channel. */
|
|
23
|
+
port?: MessagePort;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** Payloads shared by the loader task descriptor and its worker implementation. */
|
|
27
|
+
export type WorkerTaskTypes = {
|
|
28
|
+
/** Atomic input. */
|
|
29
|
+
input: WorkerTaskPayload;
|
|
30
|
+
/** Atomic output. */
|
|
31
|
+
output: WorkerTaskPayload;
|
|
32
|
+
/** Parser options. */
|
|
33
|
+
options: Record<string, any>;
|
|
34
|
+
/** Per-handle setup. */
|
|
35
|
+
initialization: WorkerTaskState;
|
|
36
|
+
/** Per-handle state. */
|
|
37
|
+
state: WorkerTaskState;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/** Public math.gl task shape used by loader adapters. */
|
|
41
|
+
export type WorkerTask = Task<WorkerTaskTypes>;
|
|
42
|
+
|
|
43
|
+
/** Normalizes optional task labels for loader progress consumers. */
|
|
44
|
+
export function normalizeTaskProgress(
|
|
45
|
+
progress: Parameters<TaskContext['reportProgress']>[0]
|
|
46
|
+
): WorkerProgress {
|
|
47
|
+
return {...progress, phase: progress.phase ?? 'process', unit: progress.unit ?? 'items'};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Detects worker execution without importing Node APIs into browser bundles. */
|
|
51
|
+
export async function isWorkerThread(): Promise<boolean> {
|
|
52
|
+
if (
|
|
53
|
+
typeof self !== 'undefined' &&
|
|
54
|
+
typeof document === 'undefined' &&
|
|
55
|
+
typeof self.postMessage === 'function'
|
|
56
|
+
)
|
|
57
|
+
return true;
|
|
58
|
+
if (typeof process !== 'undefined' && process.versions?.node) {
|
|
59
|
+
const {isMainThread} = await import('../node/worker_threads');
|
|
60
|
+
return !isMainThread;
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Installs the upstream runtime, including its Node CommonJS worker support. */
|
|
66
|
+
export const initializeTaskWorker = initializeMathTaskWorker;
|
|
@@ -66,6 +66,7 @@ function isTransferable(object: unknown) {
|
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
68
|
* Recursively drop non serializable values like functions and regexps.
|
|
69
|
+
* Preserve nested null values; a null top-level options argument normalizes to an empty object.
|
|
69
70
|
* @param object
|
|
70
71
|
*/
|
|
71
72
|
export function getTransferListForWriter(object: object | null): object {
|
|
@@ -77,6 +78,7 @@ export function getTransferListForWriter(object: object | null): object {
|
|
|
77
78
|
Object.keys(clone).forEach(key => {
|
|
78
79
|
// Typed Arrays and Arrays are passed with no change
|
|
79
80
|
if (
|
|
81
|
+
object[key] !== null &&
|
|
80
82
|
typeof object[key] === 'object' &&
|
|
81
83
|
!ArrayBuffer.isView(object[key]) &&
|
|
82
84
|
!(object[key] instanceof Array)
|
|
@@ -2,147 +2,112 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
import type {TaskProgress, TaskRunControls} from '@math.gl/core/tasks';
|
|
6
|
+
|
|
7
|
+
/** Progress from a loader task, with explicit loader phase and unit names. */
|
|
8
|
+
export type WorkerProgress = TaskProgress & {
|
|
9
|
+
/** Loader operation being measured. */
|
|
8
10
|
phase: string;
|
|
9
|
-
/**
|
|
10
|
-
completed: number;
|
|
11
|
-
/** Expected work, when known. */
|
|
12
|
-
total?: number;
|
|
13
|
-
/** Measurement unit, such as bytes, rows, or tasks. */
|
|
11
|
+
/** Measurement unit such as bytes, rows, or tasks. */
|
|
14
12
|
unit: string;
|
|
15
13
|
};
|
|
16
14
|
|
|
17
|
-
/**
|
|
18
|
-
export type
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
/** Creates a fresh browser worker; null selects the descriptor's URL. */
|
|
16
|
+
export type LoadWorker = () => Worker | null;
|
|
17
|
+
|
|
18
|
+
/** Loader task routing, cancellation, ownership, and parser options. */
|
|
19
|
+
export type WorkerOptions = Omit<TaskRunControls, 'onProgress'> & {
|
|
20
|
+
/** Receives normalized loader progress. */
|
|
22
21
|
onProgress?: (progress: WorkerProgress) => void;
|
|
23
|
-
|
|
24
|
-
CDN?: string | null;
|
|
22
|
+
/** Enables worker execution. */
|
|
25
23
|
worker?: boolean;
|
|
26
|
-
/**
|
|
24
|
+
/** Explicit batch capability for a custom worker. */
|
|
27
25
|
workerInBatches?: boolean;
|
|
26
|
+
/** Maximum concurrent task handles per descriptor. */
|
|
28
27
|
maxConcurrency?: number;
|
|
28
|
+
/** Maximum concurrency on mobile browsers. */
|
|
29
29
|
maxMobileConcurrency?: number;
|
|
30
|
-
|
|
30
|
+
/** Enables experimental Node workers for loader APIs. */
|
|
31
|
+
_nodeWorkers?: boolean;
|
|
32
|
+
/** Selects repository-local workers when set to test. */
|
|
31
33
|
_workerType?: string;
|
|
32
|
-
|
|
33
|
-
[key: string]: any;
|
|
34
|
+
/** Additional loader-specific parser options. */
|
|
35
|
+
[key: string]: any;
|
|
34
36
|
};
|
|
35
37
|
|
|
36
|
-
/**
|
|
37
|
-
|
|
38
|
-
*
|
|
39
|
-
* Returning `null` delegates to the existing URL-based worker resolution. This lets packages
|
|
40
|
-
* expose bundler-resolved module workers without removing classic worker or CDN support.
|
|
41
|
-
*/
|
|
42
|
-
export type LoadWorker = () => Worker | null;
|
|
38
|
+
/** Serializable information associated with a loader task. */
|
|
39
|
+
export type WorkerJobContext = Record<string, any>;
|
|
43
40
|
|
|
41
|
+
/** Services supplied to a loader's worker implementation. */
|
|
44
42
|
export type WorkerContext = {
|
|
45
|
-
/**
|
|
43
|
+
/** Signal for the current task. */
|
|
44
|
+
signal?: AbortSignal;
|
|
45
|
+
/** Throws when the current task has been cancelled. */
|
|
46
|
+
throwIfAborted?: () => void;
|
|
47
|
+
/** Reports normalized phase progress. */
|
|
46
48
|
reportProgress?: (progress: WorkerProgress) => void;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
/** Serializable context sent with a single worker job. */
|
|
52
|
-
export type WorkerJobContext = {
|
|
53
|
-
[key: string]: any;
|
|
49
|
+
/** Requests work on the calling thread through a task-owned MessagePort. */
|
|
50
|
+
process?: (input: any, options?: Record<string, any>, jobContext?: WorkerJobContext) => any;
|
|
54
51
|
};
|
|
55
52
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
/** Processes one loader payload. */
|
|
54
|
+
export type Process<Input = any, Output = any, Options extends object = Record<string, any>> = (
|
|
55
|
+
input: Input,
|
|
56
|
+
options?: Options,
|
|
59
57
|
context?: WorkerContext,
|
|
60
58
|
jobContext?: WorkerJobContext
|
|
61
|
-
) =>
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
59
|
+
) => Output | Promise<Output>;
|
|
60
|
+
|
|
61
|
+
/** Processes one stateful stream of loader fragments. */
|
|
62
|
+
export type ProcessInBatches<
|
|
63
|
+
Input = any,
|
|
64
|
+
Output = any,
|
|
65
|
+
Options extends object = Record<string, any>
|
|
66
|
+
> = (
|
|
67
|
+
input: AsyncIterable<Input> | Iterable<Input>,
|
|
68
|
+
options?: Options,
|
|
66
69
|
context?: WorkerContext,
|
|
67
70
|
jobContext?: WorkerJobContext
|
|
68
|
-
) => AsyncIterable<
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
) => AsyncIterable<Output>;
|
|
72
|
+
|
|
73
|
+
/** Metadata describing a loader or writer task's worker artifact. */
|
|
74
|
+
export type WorkerObject<
|
|
75
|
+
Input = any,
|
|
76
|
+
Output = any,
|
|
77
|
+
Options extends object = Record<string, any>
|
|
78
|
+
> = {
|
|
79
|
+
/** Stable format identifier. */
|
|
74
80
|
id: string;
|
|
81
|
+
/** Human-readable format name. */
|
|
75
82
|
name: string;
|
|
83
|
+
/** Published loaders.gl package containing the worker. */
|
|
76
84
|
module: string;
|
|
85
|
+
/** Version used to resolve CDN artifacts. */
|
|
77
86
|
version: string;
|
|
87
|
+
/** Built-in capability or explicit worker URL. */
|
|
78
88
|
worker?: string | boolean;
|
|
79
|
-
/** Whether the
|
|
89
|
+
/** Whether the parser supports stateful streaming. */
|
|
80
90
|
workerInBatches?: boolean;
|
|
81
|
-
/** Browser
|
|
91
|
+
/** Browser artifact name. */
|
|
82
92
|
workerFile?: string;
|
|
83
|
-
/**
|
|
93
|
+
/** Fresh browser worker factory. */
|
|
84
94
|
loadWorker?: LoadWorker;
|
|
85
|
-
/**
|
|
95
|
+
/** Node artifact name. */
|
|
86
96
|
workerNode?: string;
|
|
87
|
-
/** Repository-
|
|
97
|
+
/** Repository-local Node source used by tests. */
|
|
88
98
|
workerSourceNode?: string;
|
|
89
|
-
|
|
99
|
+
/** Default parser options. */
|
|
100
|
+
options: Record<string, any>;
|
|
101
|
+
/** Deprecated parser option mappings. */
|
|
90
102
|
deprecatedOptions?: object;
|
|
91
|
-
|
|
92
|
-
process?: Process
|
|
93
|
-
|
|
103
|
+
/** Optional caller-thread atomic implementation. */
|
|
104
|
+
process?: Process<Input, Output, Options>;
|
|
105
|
+
/** Optional caller-thread streaming implementation. */
|
|
106
|
+
processInBatches?: ProcessInBatches<Input, Output, Options>;
|
|
94
107
|
};
|
|
95
108
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
=> process-in-batches
|
|
101
|
-
|
|
102
|
-
<= input-request
|
|
103
|
-
=> input-batch
|
|
104
|
-
<= output-batch
|
|
105
|
-
=> output-ack
|
|
106
|
-
... // repeat
|
|
107
|
-
|
|
108
|
-
=> input-done
|
|
109
|
-
<= done
|
|
110
|
-
|
|
111
|
-
// or
|
|
112
|
-
|
|
113
|
-
<= error
|
|
114
|
-
*/
|
|
115
|
-
export type WorkerMessageType =
|
|
116
|
-
| 'progress'
|
|
117
|
-
| 'preload'
|
|
118
|
-
| 'process'
|
|
119
|
-
| 'done'
|
|
120
|
-
| 'error'
|
|
121
|
-
| 'process-in-batches'
|
|
122
|
-
| 'input-request'
|
|
123
|
-
| 'input-batch'
|
|
124
|
-
| 'input-done'
|
|
125
|
-
| 'output-batch'
|
|
126
|
-
| 'output-ack';
|
|
127
|
-
|
|
128
|
-
export type WorkerMessagePayload = {
|
|
129
|
-
/** Phase progress from the worker. */
|
|
130
|
-
progress?: WorkerProgress;
|
|
131
|
-
id?: number;
|
|
132
|
-
options?: {[key: string]: any};
|
|
133
|
-
context?: WorkerJobContext;
|
|
134
|
-
input?: any; // Transferable;
|
|
135
|
-
result?: any; // Transferable
|
|
136
|
-
error?: string;
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
export type WorkerMessageData = {
|
|
140
|
-
source: 'loaders.gl';
|
|
141
|
-
type: WorkerMessageType;
|
|
142
|
-
payload: WorkerMessagePayload;
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
export type WorkerMessage = {
|
|
146
|
-
type: string;
|
|
147
|
-
data: WorkerMessageData;
|
|
109
|
+
/** Services implemented by the calling thread for requests from a worker. */
|
|
110
|
+
export type CallerThreadContext = {
|
|
111
|
+
/** Processes a worker request, including its separate serialized loader context. */
|
|
112
|
+
process?: Process;
|
|
148
113
|
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Async Queue
|
|
3
|
-
* - AsyncIterable: An async iterator can be
|
|
4
|
-
* - Values can be pushed onto the queue
|
|
5
|
-
* @example
|
|
6
|
-
* const asyncQueue = new AsyncQueue();
|
|
7
|
-
* setTimeout(() => asyncQueue.enqueue('tick'), 1000);
|
|
8
|
-
* setTimeout(() => asyncQueue.enqueue(new Error('done')), 10000);
|
|
9
|
-
* for await (const value of asyncQueue) {
|
|
10
|
-
* console.log(value); // tick
|
|
11
|
-
* }
|
|
12
|
-
*/
|
|
13
|
-
export default class AsyncQueue<T> {
|
|
14
|
-
private _values;
|
|
15
|
-
private _settlers;
|
|
16
|
-
private _closed;
|
|
17
|
-
constructor();
|
|
18
|
-
/** Return an async iterator for this queue */
|
|
19
|
-
[Symbol.asyncIterator](): AsyncIterator<T>;
|
|
20
|
-
/** Push a new value - the async iterator will yield a promise resolved to this value */
|
|
21
|
-
push(value: T): void;
|
|
22
|
-
/**
|
|
23
|
-
* Push a new value - the async iterator will yield a promise resolved to this value
|
|
24
|
-
* Add an error - the async iterator will yield a promise rejected with this value
|
|
25
|
-
*/
|
|
26
|
-
enqueue(value: T | Error): void;
|
|
27
|
-
/** Indicate that we not waiting for more values - The async iterator will be done */
|
|
28
|
-
close(): void;
|
|
29
|
-
/** @returns a Promise for an IteratorResult */
|
|
30
|
-
next(): Promise<IteratorResult<T, any>>;
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=async-queue.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"async-queue.d.ts","sourceRoot":"","sources":["../../../../src/worker-utils/lib/async-queue/async-queue.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,OAAO,OAAO,UAAU,CAAC,CAAC;IAC/B,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,OAAO,CAAU;;IAQzB,8CAA8C;IAC9C,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,CAAC,CAAC;IAI1C,wFAAwF;IACxF,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI;IAIpB;;;OAGG;IACH,OAAO,CAAC,KAAK,EAAE,CAAC,GAAG,KAAK,GAAG,IAAI;IAoB/B,qFAAqF;IACrF,KAAK,IAAI,IAAI;IAUb,+CAA+C;IAC/C,IAAI,IAAI,OAAO,CAAC,cAAc,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;CAuBxC"}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
// From https://github.com/rauschma/async-iter-demo/tree/master/src under MIT license
|
|
5
|
-
// http://2ality.com/2016/10/asynchronous-iteration.html
|
|
6
|
-
/**
|
|
7
|
-
* Async Queue
|
|
8
|
-
* - AsyncIterable: An async iterator can be
|
|
9
|
-
* - Values can be pushed onto the queue
|
|
10
|
-
* @example
|
|
11
|
-
* const asyncQueue = new AsyncQueue();
|
|
12
|
-
* setTimeout(() => asyncQueue.enqueue('tick'), 1000);
|
|
13
|
-
* setTimeout(() => asyncQueue.enqueue(new Error('done')), 10000);
|
|
14
|
-
* for await (const value of asyncQueue) {
|
|
15
|
-
* console.log(value); // tick
|
|
16
|
-
* }
|
|
17
|
-
*/
|
|
18
|
-
export default class AsyncQueue {
|
|
19
|
-
_values;
|
|
20
|
-
_settlers;
|
|
21
|
-
_closed;
|
|
22
|
-
constructor() {
|
|
23
|
-
this._values = []; // enqueues > dequeues
|
|
24
|
-
this._settlers = []; // dequeues > enqueues
|
|
25
|
-
this._closed = false;
|
|
26
|
-
}
|
|
27
|
-
/** Return an async iterator for this queue */
|
|
28
|
-
[Symbol.asyncIterator]() {
|
|
29
|
-
return this;
|
|
30
|
-
}
|
|
31
|
-
/** Push a new value - the async iterator will yield a promise resolved to this value */
|
|
32
|
-
push(value) {
|
|
33
|
-
return this.enqueue(value);
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Push a new value - the async iterator will yield a promise resolved to this value
|
|
37
|
-
* Add an error - the async iterator will yield a promise rejected with this value
|
|
38
|
-
*/
|
|
39
|
-
enqueue(value) {
|
|
40
|
-
if (this._closed) {
|
|
41
|
-
throw new Error('Closed');
|
|
42
|
-
}
|
|
43
|
-
if (this._settlers.length > 0) {
|
|
44
|
-
if (this._values.length > 0) {
|
|
45
|
-
throw new Error('Illegal internal state');
|
|
46
|
-
}
|
|
47
|
-
const settler = this._settlers.shift();
|
|
48
|
-
if (value instanceof Error) {
|
|
49
|
-
settler.reject(value);
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
settler.resolve({ value });
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
this._values.push(value);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
/** Indicate that we not waiting for more values - The async iterator will be done */
|
|
60
|
-
close() {
|
|
61
|
-
while (this._settlers.length > 0) {
|
|
62
|
-
const settler = this._settlers.shift();
|
|
63
|
-
settler.resolve({ done: true });
|
|
64
|
-
}
|
|
65
|
-
this._closed = true;
|
|
66
|
-
}
|
|
67
|
-
// ITERATOR IMPLEMENTATION
|
|
68
|
-
/** @returns a Promise for an IteratorResult */
|
|
69
|
-
next() {
|
|
70
|
-
// If values in queue, yield the first value
|
|
71
|
-
if (this._values.length > 0) {
|
|
72
|
-
const value = this._values.shift();
|
|
73
|
-
if (value instanceof Error) {
|
|
74
|
-
return Promise.reject(value);
|
|
75
|
-
}
|
|
76
|
-
return Promise.resolve({ done: false, value });
|
|
77
|
-
}
|
|
78
|
-
// If queue is closed, the iterator is done
|
|
79
|
-
if (this._closed) {
|
|
80
|
-
if (this._settlers.length > 0) {
|
|
81
|
-
throw new Error('Illegal internal state');
|
|
82
|
-
}
|
|
83
|
-
return Promise.resolve({ done: true, value: undefined });
|
|
84
|
-
}
|
|
85
|
-
// Yield a promise that waits for new values to be enqueued
|
|
86
|
-
return new Promise((resolve, reject) => {
|
|
87
|
-
this._settlers.push({ resolve, reject });
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
//# sourceMappingURL=async-queue.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"async-queue.js","sourceRoot":"","sources":["../../../../src/worker-utils/lib/async-queue/async-queue.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,+BAA+B;AAC/B,oCAAoC;AAEpC,qFAAqF;AACrF,wDAAwD;AAExD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,OAAO,OAAO,UAAU;IACrB,OAAO,CAAQ;IACf,SAAS,CAAQ;IACjB,OAAO,CAAU;IAEzB;QACE,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC,CAAC,sBAAsB;QACzC,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC,CAAC,sBAAsB;QAC3C,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;IACvB,CAAC;IAED,8CAA8C;IAC9C,CAAC,MAAM,CAAC,aAAa,CAAC;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,wFAAwF;IACxF,IAAI,CAAC,KAAQ;QACX,OAAO,IAAI,CAAC,OAAO,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AI,KAAK,YAAY,KAAK,EAAE,CAAC;gBAC3B,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC/B,CAAC;YACD,OAAO,OAAO,CAAC,OAAO,CAAC,EAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAC,CAAC,CAAC;QAC/C,CAAC;QAED,2CAA2C;QAC3C,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC9B,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;YAC5C,CAAC;YACD,OAAO,OAAO,CAAC,OAAO,CAAC,EAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAC,CAAC,CAAC;QACzD,CAAC;QAED,2DAA2D;QAC3D,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAC,OAAO,EAAE,MAAM,EAAC,CAAC,CAAC;QACzC,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { WorkerMessageType, WorkerMessagePayload } from "../../types.js";
|
|
2
|
-
type WorkerMessageListener = (type: WorkerMessageType, payload: WorkerMessagePayload) => any;
|
|
3
|
-
/**
|
|
4
|
-
* Type safe wrapper for worker code
|
|
5
|
-
*/
|
|
6
|
-
export default class WorkerBody {
|
|
7
|
-
/** Check that we are actually in a worker thread */
|
|
8
|
-
static inWorkerThread(): Promise<boolean>;
|
|
9
|
-
static set onmessage(onMessage: (type: WorkerMessageType, payload: WorkerMessagePayload) => any);
|
|
10
|
-
static addEventListener(onMessage: WorkerMessageListener): Promise<void>;
|
|
11
|
-
static removeEventListener(onMessage: WorkerMessageListener): Promise<void>;
|
|
12
|
-
/**
|
|
13
|
-
* Send a message from a worker to creating thread (main thread)
|
|
14
|
-
* @param type
|
|
15
|
-
* @param payload
|
|
16
|
-
*/
|
|
17
|
-
static postMessage(type: WorkerMessageType, payload: WorkerMessagePayload): Promise<void>;
|
|
18
|
-
}
|
|
19
|
-
export {};
|
|
20
|
-
//# sourceMappingURL=worker-body.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"worker-body.d.ts","sourceRoot":"","sources":["../../../../src/worker-utils/lib/worker-farm/worker-body.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAoB,iBAAiB,EAAE,oBAAoB,EAAC,uBAAoB;AAO5F,KAAK,qBAAqB,GAAG,CAAC,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,oBAAoB,KAAK,GAAG,CAAC;AAyB7F;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,oDAAoD;WACvC,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC;IAO/C,MAAM,KAAK,SAAS,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,oBAAoB,KAAK,GAAG,EAwB9F;WAEY,gBAAgB,CAAC,SAAS,EAAE,qBAAqB;WAsBjD,mBAAmB,CAAC,SAAS,EAAE,qBAAqB;IAcjE;;;;OAIG;WACU,WAAW,CAAC,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;CAgBhG"}
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
import { getTransferList } from "../worker-utils/get-transfer-list.js";
|
|
5
|
-
// import type {TransferListItem} from '../node/worker_threads';
|
|
6
|
-
import { parentPort } from "../node/worker_threads.js";
|
|
7
|
-
/** Vile hack to defeat over-zealous bundlers from stripping out the require */
|
|
8
|
-
async function getParentPort() {
|
|
9
|
-
// const isNode = globalThis.process;
|
|
10
|
-
// let parentPort;
|
|
11
|
-
// try {
|
|
12
|
-
// // biome-ignore format: preserve intentional fixture layout
|
|
13
|
-
// eval('globalThis.parentPort = require(\'worker_threads\').parentPort'); // eslint-disable-line no-eval
|
|
14
|
-
// parentPort = globalThis.parentPort;
|
|
15
|
-
// } catch {
|
|
16
|
-
// try {
|
|
17
|
-
// // biome-ignore format: preserve intentional fixture layout
|
|
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;
|
|
26
|
-
}
|
|
27
|
-
const onMessageWrapperMap = new Map();
|
|
28
|
-
/**
|
|
29
|
-
* Type safe wrapper for worker code
|
|
30
|
-
*/
|
|
31
|
-
export default class WorkerBody {
|
|
32
|
-
/** Check that we are actually in a worker thread */
|
|
33
|
-
static async inWorkerThread() {
|
|
34
|
-
return typeof self !== 'undefined' || Boolean(await getParentPort());
|
|
35
|
-
}
|
|
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);
|
|
48
|
-
}
|
|
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
|
-
});
|
|
63
|
-
}
|
|
64
|
-
static async addEventListener(onMessage) {
|
|
65
|
-
let onMessageWrapper = onMessageWrapperMap.get(onMessage);
|
|
66
|
-
if (!onMessageWrapper) {
|
|
67
|
-
onMessageWrapper = (message) => {
|
|
68
|
-
const messageData = getWorkerMessageData(message);
|
|
69
|
-
if (!messageData) {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
onMessage(messageData.type, messageData.payload);
|
|
73
|
-
};
|
|
74
|
-
onMessageWrapperMap.set(onMessage, onMessageWrapper);
|
|
75
|
-
}
|
|
76
|
-
const parentPort = await getParentPort();
|
|
77
|
-
if (parentPort) {
|
|
78
|
-
parentPort.on('message', onMessageWrapper);
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
globalThis.addEventListener('message', onMessageWrapper);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
static async removeEventListener(onMessage) {
|
|
85
|
-
const onMessageWrapper = onMessageWrapperMap.get(onMessage);
|
|
86
|
-
onMessageWrapperMap.delete(onMessage);
|
|
87
|
-
if (!onMessageWrapper) {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
const parentPort = await getParentPort();
|
|
91
|
-
if (parentPort) {
|
|
92
|
-
parentPort.off('message', onMessageWrapper);
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
globalThis.removeEventListener('message', onMessageWrapper);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Send a message from a worker to creating thread (main thread)
|
|
100
|
-
* @param type
|
|
101
|
-
* @param payload
|
|
102
|
-
*/
|
|
103
|
-
static async postMessage(type, payload) {
|
|
104
|
-
const data = { source: 'loaders.gl', type, payload };
|
|
105
|
-
// console.log('posting message', data);
|
|
106
|
-
// Cast to Node compatible transfer list
|
|
107
|
-
const transferList = getTransferList(payload);
|
|
108
|
-
const parentPort = await getParentPort();
|
|
109
|
-
if (parentPort) {
|
|
110
|
-
parentPort.postMessage(data, transferList);
|
|
111
|
-
// console.log('posted message', data);
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
// @ts-expect-error Outside of worker scopes this call has a third parameter
|
|
115
|
-
globalThis.postMessage(data, transferList);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
// Filter out noise messages sent to workers
|
|
120
|
-
function getWorkerMessageData(message) {
|
|
121
|
-
if (!message || typeof message !== 'object') {
|
|
122
|
-
return null;
|
|
123
|
-
}
|
|
124
|
-
const messageData = 'data' in message && message.type === 'message' ? message.data : message;
|
|
125
|
-
return messageData &&
|
|
126
|
-
typeof messageData.source === 'string' &&
|
|
127
|
-
messageData.source.startsWith('loaders.gl')
|
|
128
|
-
? messageData
|
|
129
|
-
: null;
|
|
130
|
-
}
|
|
131
|
-
//# sourceMappingURL=worker-body.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"worker-body.js","sourceRoot":"","sources":["../../../../src/worker-utils/lib/worker-farm/worker-body.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,+BAA+B;AAC/B,oCAAoC;AAGpC,OAAO,EAAC,eAAe,EAAC,6CAA0C;AAClE,gEAAgE;AAChE,OAAO,EAAC,UAAU,EAAC,kCAA+B;AAMlD,+EAA+E;AAC/E,KAAK,UAAU,aAAa;IAC1B,qCAAqC;IACrC,kBAAkB;IAClB,QAAQ;IACR,gEAAgE;IAChE,2GAA2G;IAC3G,wCAAwC;IACxC,YAAY;IACZ,UAAU;IACV,kEAAkE;IAClE,2GAA2G;IAC3G,mEAAmE;IACnE,6CAA6C;IAC7C,sBAAsB;IACtB,i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OAA6B;QAC7E,MAAM,IAAI,GAAsB,EAAC,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,OAAO,EAAC,CAAC;QACtE,wCAAwC;QAExC,wCAAwC;QACxC,MAAM,YAAY,GAAG,eAAe,CAAC,OAAO,CAAuB,CAAC;QAEpE,MAAM,UAAU,GAAG,MAAM,aAAa,EAAE,CAAC;QACzC,IAAI,UAAU,EAAE,CAAC;YACf,UAAU,CAAC,WAAW,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;YAC3C,uCAAuC;QACzC,CAAC;aAAM,CAAC;YACN,4EAA4E;YAC5E,UAAU,CAAC,WAAW,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC;CACF;AAED,4CAA4C;AAC5C,SAAS,oBAAoB,CAAC,OAA2B;IACvD,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC5C,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,WAAW,GAAG,MAAM,IAAI,OAAO,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;IAC7F,OAAO,WAAW;QAChB,OAAO,WAAW,CAAC,MAAM,KAAK,QAAQ;QACtC,WAAW,CAAC,MAAM,CAAC,UAAU,CAAC,YAAY,CAAC;QAC3C,CAAC,CAAC,WAAW;QACb,CAAC,CAAC,IAAI,CAAC;AACX,CAAC"}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import WorkerPool from "./worker-pool.js";
|
|
2
|
-
import type { WorkerPoolTarget } from "./worker-pool.js";
|
|
3
|
-
/**
|
|
4
|
-
* @param maxConcurrency - max count of workers
|
|
5
|
-
* @param maxMobileConcurrency - max count of workers on mobile
|
|
6
|
-
* @param maxConcurrency - max count of workers
|
|
7
|
-
* @param reuseWorkers - if false, destroys workers when task is completed
|
|
8
|
-
* @param onDebug - callback intended to allow application to log worker pool activity
|
|
9
|
-
*/
|
|
10
|
-
export type WorkerFarmProps = {
|
|
11
|
-
maxConcurrency?: number;
|
|
12
|
-
maxMobileConcurrency?: number;
|
|
13
|
-
reuseWorkers?: boolean;
|
|
14
|
-
onDebug?: () => void;
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* Process multiple jobs with a "farm" of different workers in worker pools.
|
|
18
|
-
*/
|
|
19
|
-
export default class WorkerFarm {
|
|
20
|
-
private props;
|
|
21
|
-
private workerPools;
|
|
22
|
-
private static _workerFarm?;
|
|
23
|
-
/** Checks if workers are supported on this platform */
|
|
24
|
-
static isSupported(): boolean;
|
|
25
|
-
/** Get the singleton instance of the global worker farm */
|
|
26
|
-
static getWorkerFarm(props?: WorkerFarmProps): WorkerFarm;
|
|
27
|
-
/** get global instance with WorkerFarm.getWorkerFarm() */
|
|
28
|
-
private constructor();
|
|
29
|
-
/**
|
|
30
|
-
* Terminate all workers in the farm and abort active jobs.
|
|
31
|
-
* @param reason Optional error delivered to active jobs.
|
|
32
|
-
* @note Can free up significant memory
|
|
33
|
-
*/
|
|
34
|
-
destroy(reason?: unknown): void;
|
|
35
|
-
/**
|
|
36
|
-
* Set props used when initializing worker pools
|
|
37
|
-
* @param props
|
|
38
|
-
*/
|
|
39
|
-
setProps(props: WorkerFarmProps): void;
|
|
40
|
-
/**
|
|
41
|
-
* Returns a worker pool for the specified worker
|
|
42
|
-
* @param options Worker target used to identify and initialize the pool.
|
|
43
|
-
* @param options.name Worker name used as the base pool identity.
|
|
44
|
-
* @param options.url Worker script URL.
|
|
45
|
-
* @param options.source Inline worker source.
|
|
46
|
-
* @param options.loadWorker Built-in browser worker factory.
|
|
47
|
-
* @example
|
|
48
|
-
* const job = WorkerFarm.getWorkerFarm().getWorkerPool({name, url}).startJob(...);
|
|
49
|
-
*/
|
|
50
|
-
getWorkerPool(options: WorkerPoolTarget): WorkerPool;
|
|
51
|
-
_getWorkerPoolProps(): {
|
|
52
|
-
maxConcurrency: number | undefined;
|
|
53
|
-
maxMobileConcurrency: number | undefined;
|
|
54
|
-
reuseWorkers: boolean | undefined;
|
|
55
|
-
onDebug: (() => void) | undefined;
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
//# sourceMappingURL=worker-farm.d.ts.map
|