@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,89 +1,80 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
(() => {
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
this._closed = false;
|
|
12
|
-
}
|
|
13
|
-
/** Return an async iterator for this queue */
|
|
14
|
-
[Symbol.asyncIterator]() {
|
|
15
|
-
return this;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __esm = (fn, res, err) => function __init() {
|
|
6
|
+
if (err) throw err[0];
|
|
7
|
+
try {
|
|
8
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
9
|
+
} catch (e) {
|
|
10
|
+
throw err = [e], e;
|
|
16
11
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
/** Indicate that we not waiting for more values - The async iterator will be done */
|
|
44
|
-
close() {
|
|
45
|
-
while (this._settlers.length > 0) {
|
|
46
|
-
const settler = this._settlers.shift();
|
|
47
|
-
settler.resolve({ done: true });
|
|
48
|
-
}
|
|
49
|
-
this._closed = true;
|
|
50
|
-
}
|
|
51
|
-
// ITERATOR IMPLEMENTATION
|
|
52
|
-
/** @returns a Promise for an IteratorResult */
|
|
53
|
-
next() {
|
|
54
|
-
if (this._values.length > 0) {
|
|
55
|
-
const value = this._values.shift();
|
|
56
|
-
if (value instanceof Error) {
|
|
57
|
-
return Promise.reject(value);
|
|
12
|
+
};
|
|
13
|
+
var __export = (target, all) => {
|
|
14
|
+
for (var name in all)
|
|
15
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// src/worker-utils/lib/node/worker_threads-browser.ts
|
|
19
|
+
var worker_threads_browser_exports = {};
|
|
20
|
+
__export(worker_threads_browser_exports, {
|
|
21
|
+
NodeWorker: () => NodeWorker,
|
|
22
|
+
parentPort: () => parentPort2
|
|
23
|
+
});
|
|
24
|
+
var NodeWorker, parentPort2;
|
|
25
|
+
var init_worker_threads_browser = __esm({
|
|
26
|
+
"src/worker-utils/lib/node/worker_threads-browser.ts"() {
|
|
27
|
+
"use strict";
|
|
28
|
+
NodeWorker = class {
|
|
29
|
+
/** Restores the native worker constructor when this browser shim is embedded in a Node bundle. */
|
|
30
|
+
constructor(...arguments_) {
|
|
31
|
+
const runtimeProcess = globalThis.process;
|
|
32
|
+
const WorkerConstructor = runtimeProcess?.getBuiltinModule?.("node:worker_threads").Worker;
|
|
33
|
+
if (WorkerConstructor) {
|
|
34
|
+
return new WorkerConstructor(...arguments_);
|
|
35
|
+
}
|
|
58
36
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (this._closed) {
|
|
62
|
-
if (this._settlers.length > 0) {
|
|
63
|
-
throw new Error("Illegal internal state");
|
|
37
|
+
/** No-op browser fallback matching the native Worker API. */
|
|
38
|
+
terminate() {
|
|
64
39
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return new Promise((resolve, reject) => {
|
|
68
|
-
this._settlers.push({ resolve, reject });
|
|
69
|
-
});
|
|
40
|
+
};
|
|
41
|
+
parentPort2 = null;
|
|
70
42
|
}
|
|
71
|
-
};
|
|
43
|
+
});
|
|
72
44
|
|
|
73
|
-
//
|
|
45
|
+
// ../../node_modules/@math.gl/core/dist/worker-utils/lib/node/worker_threads-browser.js
|
|
46
|
+
var parentPort = globalThis.process?.getBuiltinModule?.("node:worker_threads")?.parentPort ?? null;
|
|
47
|
+
|
|
48
|
+
// ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-utils/get-transfer-list.js
|
|
74
49
|
function getTransferList(object, recursive = true, transfers) {
|
|
75
50
|
const transfersSet = transfers || /* @__PURE__ */ new Set();
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
51
|
+
const seen = /* @__PURE__ */ new Set();
|
|
52
|
+
function visit(value) {
|
|
53
|
+
if (!value || typeof value !== "object" || seen.has(value))
|
|
54
|
+
return;
|
|
55
|
+
seen.add(value);
|
|
56
|
+
if (isTransferable(value))
|
|
57
|
+
transfersSet.add(value);
|
|
58
|
+
else if (ArrayBuffer.isView(value)) {
|
|
59
|
+
if (isTransferable(value.buffer))
|
|
60
|
+
transfersSet.add(value.buffer);
|
|
61
|
+
} else if (recursive && typeof MessageChannel !== "undefined" && value instanceof MessageChannel) {
|
|
62
|
+
visit(value.port1);
|
|
63
|
+
visit(value.port2);
|
|
64
|
+
} else if (recursive && value instanceof Map) {
|
|
65
|
+
for (const [key, item] of value) {
|
|
66
|
+
visit(key);
|
|
67
|
+
visit(item);
|
|
68
|
+
}
|
|
69
|
+
} else if (recursive && value instanceof Set) {
|
|
70
|
+
for (const item of value)
|
|
71
|
+
visit(item);
|
|
72
|
+
} else if (recursive) {
|
|
73
|
+
for (const key of Object.keys(value))
|
|
74
|
+
visit(value[key]);
|
|
85
75
|
}
|
|
86
76
|
}
|
|
77
|
+
visit(object);
|
|
87
78
|
return transfers === void 0 ? Array.from(transfersSet) : [];
|
|
88
79
|
}
|
|
89
80
|
function isTransferable(object) {
|
|
@@ -105,10 +96,7 @@
|
|
|
105
96
|
return false;
|
|
106
97
|
}
|
|
107
98
|
|
|
108
|
-
//
|
|
109
|
-
var parentPort = null;
|
|
110
|
-
|
|
111
|
-
// src/worker-utils/lib/worker-farm/worker-body.ts
|
|
99
|
+
// ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-farm/worker-body.js
|
|
112
100
|
async function getParentPort() {
|
|
113
101
|
return parentPort;
|
|
114
102
|
}
|
|
@@ -116,23 +104,24 @@
|
|
|
116
104
|
var WorkerBody = class {
|
|
117
105
|
/** Check that we are actually in a worker thread */
|
|
118
106
|
static async inWorkerThread() {
|
|
119
|
-
|
|
107
|
+
const workerGlobalScope = globalThis.WorkerGlobalScope;
|
|
108
|
+
return typeof workerGlobalScope === "function" && globalThis instanceof workerGlobalScope || Boolean(await getParentPort());
|
|
120
109
|
}
|
|
121
110
|
/*
|
|
122
111
|
* (type: WorkerMessageType, payload: WorkerMessagePayload) => any
|
|
123
112
|
*/
|
|
124
113
|
static set onmessage(onMessage) {
|
|
125
114
|
async function handleMessage(message) {
|
|
126
|
-
const
|
|
127
|
-
const { type, payload } =
|
|
115
|
+
const parentPort3 = await getParentPort();
|
|
116
|
+
const { type, payload } = parentPort3 ? message : message.data;
|
|
128
117
|
onMessage(type, payload);
|
|
129
118
|
}
|
|
130
|
-
getParentPort().then((
|
|
131
|
-
if (
|
|
132
|
-
|
|
119
|
+
getParentPort().then((parentPort3) => {
|
|
120
|
+
if (parentPort3) {
|
|
121
|
+
parentPort3.on("message", (message) => {
|
|
133
122
|
handleMessage(message);
|
|
134
123
|
});
|
|
135
|
-
|
|
124
|
+
parentPort3.on("exit", () => console.debug("Node worker closing"));
|
|
136
125
|
} else {
|
|
137
126
|
globalThis.onmessage = handleMessage;
|
|
138
127
|
}
|
|
@@ -150,9 +139,9 @@
|
|
|
150
139
|
};
|
|
151
140
|
onMessageWrapperMap.set(onMessage, onMessageWrapper);
|
|
152
141
|
}
|
|
153
|
-
const
|
|
154
|
-
if (
|
|
155
|
-
|
|
142
|
+
const parentPort3 = await getParentPort();
|
|
143
|
+
if (parentPort3) {
|
|
144
|
+
parentPort3.on("message", onMessageWrapper);
|
|
156
145
|
} else {
|
|
157
146
|
globalThis.addEventListener("message", onMessageWrapper);
|
|
158
147
|
}
|
|
@@ -163,9 +152,9 @@
|
|
|
163
152
|
if (!onMessageWrapper) {
|
|
164
153
|
return;
|
|
165
154
|
}
|
|
166
|
-
const
|
|
167
|
-
if (
|
|
168
|
-
|
|
155
|
+
const parentPort3 = await getParentPort();
|
|
156
|
+
if (parentPort3) {
|
|
157
|
+
parentPort3.off("message", onMessageWrapper);
|
|
169
158
|
} else {
|
|
170
159
|
globalThis.removeEventListener("message", onMessageWrapper);
|
|
171
160
|
}
|
|
@@ -175,12 +164,12 @@
|
|
|
175
164
|
* @param type
|
|
176
165
|
* @param payload
|
|
177
166
|
*/
|
|
178
|
-
static async postMessage(type, payload) {
|
|
167
|
+
static async postMessage(type, payload, copy = false) {
|
|
179
168
|
const data = { source: "loaders.gl", type, payload };
|
|
180
|
-
const transferList = getTransferList(payload);
|
|
181
|
-
const
|
|
182
|
-
if (
|
|
183
|
-
|
|
169
|
+
const transferList = copy ? [] : getTransferList(payload);
|
|
170
|
+
const parentPort3 = await getParentPort();
|
|
171
|
+
if (parentPort3) {
|
|
172
|
+
parentPort3.postMessage(data, transferList);
|
|
184
173
|
} else {
|
|
185
174
|
globalThis.postMessage(data, transferList);
|
|
186
175
|
}
|
|
@@ -194,11 +183,125 @@
|
|
|
194
183
|
return messageData && typeof messageData.source === "string" && messageData.source.startsWith("loaders.gl") ? messageData : null;
|
|
195
184
|
}
|
|
196
185
|
|
|
197
|
-
//
|
|
186
|
+
// ../../node_modules/@math.gl/core/dist/worker-utils/lib/async-queue/async-queue.js
|
|
187
|
+
var AsyncQueue = class {
|
|
188
|
+
constructor() {
|
|
189
|
+
this._values = [];
|
|
190
|
+
this._settlers = [];
|
|
191
|
+
this._closed = false;
|
|
192
|
+
}
|
|
193
|
+
/** Return an async iterator for this queue */
|
|
194
|
+
[Symbol.asyncIterator]() {
|
|
195
|
+
return this;
|
|
196
|
+
}
|
|
197
|
+
/** Push a new value - the async iterator will yield a promise resolved to this value */
|
|
198
|
+
push(value) {
|
|
199
|
+
return this.enqueue(value);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Push a new value - the async iterator will yield a promise resolved to this value
|
|
203
|
+
* Add an error - the async iterator will yield a promise rejected with this value
|
|
204
|
+
*/
|
|
205
|
+
enqueue(value) {
|
|
206
|
+
if (this._closed) {
|
|
207
|
+
throw new Error("Closed");
|
|
208
|
+
}
|
|
209
|
+
if (this._settlers.length > 0) {
|
|
210
|
+
if (this._values.length > 0) {
|
|
211
|
+
throw new Error("Illegal internal state");
|
|
212
|
+
}
|
|
213
|
+
const settler = this._settlers.shift();
|
|
214
|
+
if (value instanceof Error) {
|
|
215
|
+
settler.reject(value);
|
|
216
|
+
} else {
|
|
217
|
+
settler.resolve({ value });
|
|
218
|
+
}
|
|
219
|
+
} else {
|
|
220
|
+
this._values.push(value);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/** Indicate that we not waiting for more values - The async iterator will be done */
|
|
224
|
+
close() {
|
|
225
|
+
while (this._settlers.length > 0) {
|
|
226
|
+
const settler = this._settlers.shift();
|
|
227
|
+
settler.resolve({ done: true });
|
|
228
|
+
}
|
|
229
|
+
this._closed = true;
|
|
230
|
+
}
|
|
231
|
+
// ITERATOR IMPLEMENTATION
|
|
232
|
+
/** @returns a Promise for an IteratorResult */
|
|
233
|
+
next() {
|
|
234
|
+
if (this._values.length > 0) {
|
|
235
|
+
const value = this._values.shift();
|
|
236
|
+
if (value instanceof Error) {
|
|
237
|
+
return Promise.reject(value);
|
|
238
|
+
}
|
|
239
|
+
return Promise.resolve({ done: false, value });
|
|
240
|
+
}
|
|
241
|
+
if (this._closed) {
|
|
242
|
+
if (this._settlers.length > 0) {
|
|
243
|
+
throw new Error("Illegal internal state");
|
|
244
|
+
}
|
|
245
|
+
return Promise.resolve({ done: true, value: void 0 });
|
|
246
|
+
}
|
|
247
|
+
return new Promise((resolve, reject) => {
|
|
248
|
+
this._settlers.push({ resolve, reject });
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
// ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-api/shared-state.js
|
|
254
|
+
var SharedWorkerState = class {
|
|
255
|
+
constructor(buffer) {
|
|
256
|
+
if (typeof SharedArrayBuffer === "undefined" || !(buffer instanceof SharedArrayBuffer) || buffer.byteLength !== 16)
|
|
257
|
+
throw new Error("Expected a 16-byte shared worker control buffer");
|
|
258
|
+
this.buffer = buffer;
|
|
259
|
+
this.values = new Int32Array(buffer);
|
|
260
|
+
}
|
|
261
|
+
get snapshot() {
|
|
262
|
+
return {
|
|
263
|
+
cancelled: Atomics.load(this.values, 0) !== 0,
|
|
264
|
+
completed: Atomics.load(this.values, 1),
|
|
265
|
+
total: Atomics.load(this.values, 2),
|
|
266
|
+
revision: Atomics.load(this.values, 3)
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
cancel() {
|
|
270
|
+
Atomics.store(this.values, 0, 1);
|
|
271
|
+
Atomics.add(this.values, 3, 1);
|
|
272
|
+
Atomics.notify(this.values, 0);
|
|
273
|
+
}
|
|
274
|
+
throwIfCancelled() {
|
|
275
|
+
if (Atomics.load(this.values, 0) !== 0) {
|
|
276
|
+
const error = new Error("Shared worker task was cancelled");
|
|
277
|
+
error.name = "AbortError";
|
|
278
|
+
throw error;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
/** Integer counters for application-defined work; messages still carry phase names and units. */
|
|
282
|
+
setProgress(completed, total = -1) {
|
|
283
|
+
if (!Number.isInteger(completed) || completed < 0 || completed > 2147483647 || !Number.isInteger(total) || total < -1 || total > 2147483647) {
|
|
284
|
+
throw new RangeError("Shared progress requires nonnegative int32 counts (or total -1)");
|
|
285
|
+
}
|
|
286
|
+
Atomics.store(this.values, 1, completed);
|
|
287
|
+
Atomics.store(this.values, 2, total);
|
|
288
|
+
Atomics.add(this.values, 3, 1);
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
// ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-api/validate-output-ownership.js
|
|
293
|
+
function validateOutputOwnership(ownership) {
|
|
294
|
+
if (ownership !== void 0 && ownership !== "copy" && ownership !== "transfer") {
|
|
295
|
+
throw new Error("Invalid worker output ownership");
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// ../../node_modules/@math.gl/core/dist/worker-utils/lib/worker-api/create-worker.js
|
|
198
300
|
var requestId = 0;
|
|
301
|
+
var activeController = null;
|
|
199
302
|
var activeInputBatches = null;
|
|
200
303
|
var activeOutputAcknowledgements = null;
|
|
201
|
-
async function createWorker(
|
|
304
|
+
async function createWorker(process2, processInBatches2, preload) {
|
|
202
305
|
if (!await WorkerBody.inWorkerThread()) {
|
|
203
306
|
return;
|
|
204
307
|
}
|
|
@@ -206,27 +309,59 @@
|
|
|
206
309
|
process: processOnMainThread
|
|
207
310
|
};
|
|
208
311
|
WorkerBody.onmessage = async (type, payload) => {
|
|
312
|
+
if (type === "cancel") {
|
|
313
|
+
activeController?.abort();
|
|
314
|
+
activeInputBatches?.close();
|
|
315
|
+
activeOutputAcknowledgements?.close();
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
const controller = type === "process" || type === "process-in-batches" ? new AbortController() : void 0;
|
|
319
|
+
if (controller)
|
|
320
|
+
activeController = controller;
|
|
321
|
+
const startedAt = performance.now();
|
|
209
322
|
const reporter = type === "process" || type === "process-in-batches" ? createProgressReporter() : void 0;
|
|
210
|
-
|
|
323
|
+
let sharedState;
|
|
324
|
+
const throwIfAborted = () => {
|
|
325
|
+
controller?.signal.throwIfAborted();
|
|
326
|
+
sharedState?.throwIfCancelled();
|
|
327
|
+
};
|
|
328
|
+
const jobContext = {
|
|
329
|
+
...context,
|
|
330
|
+
signal: controller?.signal,
|
|
331
|
+
sharedState,
|
|
332
|
+
throwIfAborted,
|
|
333
|
+
reportProgress: (progress) => {
|
|
334
|
+
if (!controller?.signal.aborted && !sharedState?.snapshot.cancelled)
|
|
335
|
+
reporter?.report(progress);
|
|
336
|
+
}
|
|
337
|
+
};
|
|
211
338
|
try {
|
|
339
|
+
if (controller && payload.options?.["sharedState"]) {
|
|
340
|
+
sharedState = new SharedWorkerState(payload.options["sharedState"]);
|
|
341
|
+
jobContext.sharedState = sharedState;
|
|
342
|
+
}
|
|
212
343
|
switch (type) {
|
|
213
344
|
case "preload":
|
|
345
|
+
await preload?.();
|
|
214
346
|
WorkerBody.postMessage("done", {});
|
|
215
347
|
break;
|
|
216
348
|
case "process":
|
|
217
|
-
|
|
349
|
+
throwIfAborted();
|
|
350
|
+
validateOutputOwnership(payload.options?.["outputOwnership"]);
|
|
351
|
+
if (!process2) {
|
|
218
352
|
throw new Error("Worker does not support atomic processing");
|
|
219
353
|
}
|
|
220
|
-
const result = await
|
|
221
|
-
|
|
222
|
-
payload.options || {},
|
|
223
|
-
jobContext,
|
|
224
|
-
payload.context || {}
|
|
225
|
-
);
|
|
354
|
+
const result = await process2(payload.input, payload.options || {}, jobContext, payload.context || {});
|
|
355
|
+
throwIfAborted();
|
|
226
356
|
reporter?.finish();
|
|
227
|
-
WorkerBody.postMessage("done", {
|
|
357
|
+
await WorkerBody.postMessage("done", {
|
|
358
|
+
result,
|
|
359
|
+
executionMs: performance.now() - startedAt
|
|
360
|
+
}, payload.options?.["outputOwnership"] === "copy");
|
|
228
361
|
break;
|
|
229
362
|
case "process-in-batches":
|
|
363
|
+
throwIfAborted();
|
|
364
|
+
validateOutputOwnership(payload.options?.["outputOwnership"]);
|
|
230
365
|
if (!processInBatches2) {
|
|
231
366
|
throw new Error("Worker does not support batched processing");
|
|
232
367
|
}
|
|
@@ -235,18 +370,15 @@
|
|
|
235
370
|
activeInputBatches = inputBatches;
|
|
236
371
|
activeOutputAcknowledgements = outputAcknowledgements;
|
|
237
372
|
try {
|
|
238
|
-
const resultIterator = processInBatches2(
|
|
239
|
-
createDemandDrivenIterator(inputBatches),
|
|
240
|
-
payload.options || {},
|
|
241
|
-
jobContext,
|
|
242
|
-
payload.context || {}
|
|
243
|
-
);
|
|
373
|
+
const resultIterator = processInBatches2(createDemandDrivenIterator(inputBatches), payload.options || {}, jobContext, payload.context || {});
|
|
244
374
|
for await (const batch of resultIterator) {
|
|
245
|
-
|
|
375
|
+
throwIfAborted();
|
|
376
|
+
await WorkerBody.postMessage("output-batch", { result: batch }, payload.options?.["outputOwnership"] === "copy");
|
|
246
377
|
await outputAcknowledgements.next();
|
|
247
378
|
}
|
|
379
|
+
throwIfAborted();
|
|
248
380
|
reporter?.finish();
|
|
249
|
-
await WorkerBody.postMessage("done", {});
|
|
381
|
+
await WorkerBody.postMessage("done", { executionMs: performance.now() - startedAt });
|
|
250
382
|
} finally {
|
|
251
383
|
activeInputBatches = null;
|
|
252
384
|
activeOutputAcknowledgements = null;
|
|
@@ -273,11 +405,18 @@
|
|
|
273
405
|
default:
|
|
274
406
|
}
|
|
275
407
|
} catch (error) {
|
|
276
|
-
reporter?.finish();
|
|
408
|
+
reporter?.finish(controller?.signal.aborted || sharedState?.snapshot.cancelled);
|
|
277
409
|
const message = error instanceof Error ? error.message : "";
|
|
278
|
-
WorkerBody.postMessage("error", {
|
|
410
|
+
await WorkerBody.postMessage("error", {
|
|
411
|
+
error: message,
|
|
412
|
+
errorName: error instanceof Error ? error.name : "Error"
|
|
413
|
+
});
|
|
414
|
+
} finally {
|
|
415
|
+
if (controller && activeController === controller)
|
|
416
|
+
activeController = null;
|
|
279
417
|
}
|
|
280
418
|
};
|
|
419
|
+
await WorkerBody.postMessage("ready", {});
|
|
281
420
|
}
|
|
282
421
|
async function* createDemandDrivenIterator(inputBatches) {
|
|
283
422
|
while (true) {
|
|
@@ -290,61 +429,355 @@
|
|
|
290
429
|
}
|
|
291
430
|
}
|
|
292
431
|
function processOnMainThread(arrayBuffer, options = {}, jobContext = {}) {
|
|
432
|
+
const signal = activeController?.signal;
|
|
433
|
+
signal?.throwIfAborted();
|
|
293
434
|
return new Promise((resolve, reject) => {
|
|
294
435
|
const id = requestId++;
|
|
295
|
-
const
|
|
296
|
-
|
|
436
|
+
const cleanup = () => {
|
|
437
|
+
signal?.removeEventListener("abort", abort);
|
|
438
|
+
void WorkerBody.removeEventListener(onMessage);
|
|
439
|
+
};
|
|
440
|
+
const abort = () => {
|
|
441
|
+
cleanup();
|
|
442
|
+
reject(signal?.reason);
|
|
443
|
+
};
|
|
444
|
+
const onMessage = (type, payload) => {
|
|
445
|
+
if (payload.id !== id)
|
|
297
446
|
return;
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
case "error":
|
|
305
|
-
WorkerBody.removeEventListener(onMessage);
|
|
306
|
-
reject(payload2.error);
|
|
307
|
-
break;
|
|
308
|
-
default:
|
|
447
|
+
if (type === "done") {
|
|
448
|
+
cleanup();
|
|
449
|
+
resolve(payload.result);
|
|
450
|
+
} else if (type === "error") {
|
|
451
|
+
cleanup();
|
|
452
|
+
reject(payload.error);
|
|
309
453
|
}
|
|
310
454
|
};
|
|
311
|
-
WorkerBody.addEventListener(onMessage)
|
|
312
|
-
|
|
313
|
-
|
|
455
|
+
void WorkerBody.addEventListener(onMessage).then(async () => {
|
|
456
|
+
if (signal?.aborted) {
|
|
457
|
+
abort();
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
461
|
+
await WorkerBody.postMessage("process", {
|
|
462
|
+
id,
|
|
463
|
+
input: arrayBuffer,
|
|
464
|
+
options,
|
|
465
|
+
context: jobContext
|
|
466
|
+
});
|
|
467
|
+
}).catch((error) => {
|
|
468
|
+
cleanup();
|
|
469
|
+
reject(error);
|
|
470
|
+
});
|
|
314
471
|
});
|
|
315
472
|
}
|
|
316
473
|
function createProgressReporter() {
|
|
317
|
-
let
|
|
474
|
+
let pending2;
|
|
318
475
|
let finished = false;
|
|
319
476
|
let scheduled = false;
|
|
320
477
|
const flush = () => {
|
|
321
478
|
scheduled = false;
|
|
322
|
-
if (
|
|
323
|
-
WorkerBody.postMessage("progress", { progress:
|
|
324
|
-
|
|
479
|
+
if (pending2) {
|
|
480
|
+
WorkerBody.postMessage("progress", { progress: pending2 });
|
|
481
|
+
pending2 = void 0;
|
|
325
482
|
}
|
|
326
483
|
};
|
|
327
484
|
return {
|
|
328
485
|
/** Records progress while retaining phase transitions. */
|
|
329
486
|
report(progress) {
|
|
330
|
-
if (finished)
|
|
331
|
-
|
|
332
|
-
|
|
487
|
+
if (finished)
|
|
488
|
+
return;
|
|
489
|
+
if (pending2 && pending2.phase !== progress.phase)
|
|
490
|
+
flush();
|
|
491
|
+
pending2 = { ...progress };
|
|
333
492
|
if (!scheduled) {
|
|
334
493
|
scheduled = true;
|
|
335
494
|
setTimeout(flush, 0);
|
|
336
495
|
}
|
|
337
496
|
},
|
|
338
497
|
/** Flushes final progress and suppresses reports from stale callbacks. */
|
|
339
|
-
finish() {
|
|
498
|
+
finish(discard = false) {
|
|
499
|
+
if (discard)
|
|
500
|
+
pending2 = void 0;
|
|
340
501
|
flush();
|
|
341
502
|
finished = true;
|
|
342
503
|
}
|
|
343
504
|
};
|
|
344
505
|
}
|
|
345
506
|
|
|
507
|
+
// ../../node_modules/@math.gl/core/dist/worker-utils/index.js
|
|
508
|
+
var import_meta = {};
|
|
509
|
+
var path = typeof __filename === "string" ? __filename.replace(/\\/g, "/") : "";
|
|
510
|
+
var moduleUrl = path ? `file://${path.startsWith("/") ? "" : "/"}${encodeURI(path).replace(/#/g, "%23").replace(/\?/g, "%3F")}` : import_meta.url;
|
|
511
|
+
|
|
512
|
+
// ../../node_modules/@math.gl/core/dist/tasks/task-preload.js
|
|
513
|
+
var pending = /* @__PURE__ */ new WeakMap();
|
|
514
|
+
var loaded = /* @__PURE__ */ new WeakSet();
|
|
515
|
+
function preloadTaskCode(task, signal) {
|
|
516
|
+
if (!task.preload)
|
|
517
|
+
return Promise.resolve();
|
|
518
|
+
let promise = pending.get(task);
|
|
519
|
+
if (!promise) {
|
|
520
|
+
promise = Promise.resolve().then(() => task.preload()).then(() => {
|
|
521
|
+
loaded.add(task);
|
|
522
|
+
});
|
|
523
|
+
pending.set(task, promise);
|
|
524
|
+
void promise.catch(() => pending.delete(task));
|
|
525
|
+
}
|
|
526
|
+
return withSignal(promise, signal);
|
|
527
|
+
}
|
|
528
|
+
function withSignal(operation, signal) {
|
|
529
|
+
if (!signal)
|
|
530
|
+
return operation;
|
|
531
|
+
return new Promise((resolve, reject) => {
|
|
532
|
+
const abort = () => {
|
|
533
|
+
signal.removeEventListener("abort", abort);
|
|
534
|
+
reject(signal.reason);
|
|
535
|
+
};
|
|
536
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
537
|
+
if (signal.aborted)
|
|
538
|
+
abort();
|
|
539
|
+
operation.then((value) => {
|
|
540
|
+
signal.removeEventListener("abort", abort);
|
|
541
|
+
resolve(value);
|
|
542
|
+
}, (error) => {
|
|
543
|
+
signal.removeEventListener("abort", abort);
|
|
544
|
+
reject(error);
|
|
545
|
+
});
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
// ../../node_modules/@math.gl/core/dist/tasks/task-runtime.js
|
|
550
|
+
function assertPayload(value) {
|
|
551
|
+
if (!value || typeof value !== "object" || Object.getPrototypeOf(value) !== Object.prototype) {
|
|
552
|
+
throw new TypeError("Task payloads must be plain objects with named fields");
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
function taskContext(state, context = {}) {
|
|
556
|
+
const signal = context.signal ?? new AbortController().signal;
|
|
557
|
+
return {
|
|
558
|
+
state,
|
|
559
|
+
signal,
|
|
560
|
+
throwIfAborted: () => {
|
|
561
|
+
signal.throwIfAborted();
|
|
562
|
+
context.throwIfAborted?.();
|
|
563
|
+
},
|
|
564
|
+
reportProgress: (progress) => context.reportProgress?.({
|
|
565
|
+
...progress,
|
|
566
|
+
phase: progress.phase ?? "process",
|
|
567
|
+
unit: progress.unit ?? "items"
|
|
568
|
+
})
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
var TaskRuntime = class {
|
|
572
|
+
constructor(task) {
|
|
573
|
+
this.task = task;
|
|
574
|
+
this.initialized = false;
|
|
575
|
+
}
|
|
576
|
+
async initialize(input, context = {}) {
|
|
577
|
+
if (this.initialized)
|
|
578
|
+
throw new Error("Task is already initialized");
|
|
579
|
+
assertPayload(input);
|
|
580
|
+
await preloadTaskCode(this.task, context.signal);
|
|
581
|
+
context.signal?.throwIfAborted();
|
|
582
|
+
this.state = await this.task.initialize?.(input, taskContext(void 0, context));
|
|
583
|
+
this.initialized = true;
|
|
584
|
+
return {};
|
|
585
|
+
}
|
|
586
|
+
async destroy() {
|
|
587
|
+
if (this.initialized) {
|
|
588
|
+
this.initialized = false;
|
|
589
|
+
const state = this.state;
|
|
590
|
+
this.state = void 0;
|
|
591
|
+
if (this.task.initialize)
|
|
592
|
+
await this.task.destroy?.(state);
|
|
593
|
+
}
|
|
594
|
+
return {};
|
|
595
|
+
}
|
|
596
|
+
async process(input, options, context = {}) {
|
|
597
|
+
if (!this.initialized)
|
|
598
|
+
throw new Error("Task is not initialized");
|
|
599
|
+
if (!this.task.process)
|
|
600
|
+
throw new Error("Task has no atomic processor");
|
|
601
|
+
assertPayload(input);
|
|
602
|
+
const result = await this.task.process(input, options, taskContext(this.state, context));
|
|
603
|
+
assertPayload(result);
|
|
604
|
+
return result;
|
|
605
|
+
}
|
|
606
|
+
async *stream(inputs, options, context = {}) {
|
|
607
|
+
if (!this.initialized)
|
|
608
|
+
throw new Error("Task is not initialized");
|
|
609
|
+
if (!this.task.processInBatches)
|
|
610
|
+
throw new Error("Task has no streaming processor");
|
|
611
|
+
for await (const output of this.task.processInBatches(inputs, options, taskContext(this.state, context))) {
|
|
612
|
+
assertPayload(output);
|
|
613
|
+
yield output;
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
};
|
|
617
|
+
async function initializeTaskWorker(task) {
|
|
618
|
+
if (!await WorkerBody.inWorkerThread())
|
|
619
|
+
throw new Error("initializeTaskWorker must run inside a worker");
|
|
620
|
+
if (installed)
|
|
621
|
+
throw new Error("A task is already installed in this worker");
|
|
622
|
+
installed = true;
|
|
623
|
+
const runtime = new TaskRuntime(task);
|
|
624
|
+
let streamOptions = {};
|
|
625
|
+
return createWorker(async (request, _options, context) => {
|
|
626
|
+
switch (request.operation) {
|
|
627
|
+
case "initialize":
|
|
628
|
+
return runtime.initialize(request.input, context);
|
|
629
|
+
case "destroy":
|
|
630
|
+
return runtime.destroy();
|
|
631
|
+
case "stream-options":
|
|
632
|
+
streamOptions = request.options;
|
|
633
|
+
return {};
|
|
634
|
+
case "process":
|
|
635
|
+
return runtime.process(request.input, request.options, context);
|
|
636
|
+
default:
|
|
637
|
+
throw new Error("Unknown task operation");
|
|
638
|
+
}
|
|
639
|
+
}, async function* (inputs, _options, context) {
|
|
640
|
+
async function* batches() {
|
|
641
|
+
for await (const input of inputs) {
|
|
642
|
+
assertPayload(input);
|
|
643
|
+
yield input;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
try {
|
|
647
|
+
yield* runtime.stream(batches(), streamOptions, context);
|
|
648
|
+
} finally {
|
|
649
|
+
streamOptions = {};
|
|
650
|
+
}
|
|
651
|
+
}, () => preloadTaskCode(task));
|
|
652
|
+
}
|
|
653
|
+
var installed = false;
|
|
654
|
+
|
|
655
|
+
// src/worker-utils/lib/worker-api/task-runtime.ts
|
|
656
|
+
function normalizeTaskProgress(progress) {
|
|
657
|
+
return { ...progress, phase: progress.phase ?? "process", unit: progress.unit ?? "items" };
|
|
658
|
+
}
|
|
659
|
+
async function isWorkerThread() {
|
|
660
|
+
if (typeof self !== "undefined" && typeof document === "undefined" && typeof self.postMessage === "function")
|
|
661
|
+
return true;
|
|
662
|
+
if (typeof process !== "undefined" && process.versions?.node) {
|
|
663
|
+
const { isMainThread } = await Promise.resolve().then(() => (init_worker_threads_browser(), worker_threads_browser_exports));
|
|
664
|
+
return !isMainThread;
|
|
665
|
+
}
|
|
666
|
+
return false;
|
|
667
|
+
}
|
|
668
|
+
var initializeTaskWorker2 = initializeTaskWorker;
|
|
669
|
+
|
|
670
|
+
// src/worker-utils/lib/worker-utils/get-transfer-list.ts
|
|
671
|
+
function getTransferList2(object, recursive = true, transfers) {
|
|
672
|
+
const transfersSet = transfers || /* @__PURE__ */ new Set();
|
|
673
|
+
if (!object) {
|
|
674
|
+
} else if (isTransferable2(object)) {
|
|
675
|
+
transfersSet.add(object);
|
|
676
|
+
} else if (isTransferable2(object.buffer)) {
|
|
677
|
+
transfersSet.add(object.buffer);
|
|
678
|
+
} else if (ArrayBuffer.isView(object)) {
|
|
679
|
+
} else if (recursive && typeof object === "object") {
|
|
680
|
+
for (const key in object) {
|
|
681
|
+
getTransferList2(object[key], recursive, transfersSet);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
return transfers === void 0 ? Array.from(transfersSet) : [];
|
|
685
|
+
}
|
|
686
|
+
function isTransferable2(object) {
|
|
687
|
+
if (!object) {
|
|
688
|
+
return false;
|
|
689
|
+
}
|
|
690
|
+
if (object instanceof ArrayBuffer) {
|
|
691
|
+
return true;
|
|
692
|
+
}
|
|
693
|
+
if (typeof MessagePort !== "undefined" && object instanceof MessagePort) {
|
|
694
|
+
return true;
|
|
695
|
+
}
|
|
696
|
+
if (typeof ImageBitmap !== "undefined" && object instanceof ImageBitmap) {
|
|
697
|
+
return true;
|
|
698
|
+
}
|
|
699
|
+
if (typeof OffscreenCanvas !== "undefined" && object instanceof OffscreenCanvas) {
|
|
700
|
+
return true;
|
|
701
|
+
}
|
|
702
|
+
return false;
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
// src/worker-utils/lib/worker-api/create-worker.ts
|
|
706
|
+
async function createWorker2(process2, processInBatches2) {
|
|
707
|
+
if (!await isWorkerThread()) return;
|
|
708
|
+
await initializeTaskWorker2(createWorkerTask(process2, processInBatches2));
|
|
709
|
+
}
|
|
710
|
+
function createWorkerTask(process2, processInBatches2) {
|
|
711
|
+
return {
|
|
712
|
+
id: "loaders.gl",
|
|
713
|
+
initialize: (state) => state,
|
|
714
|
+
destroy: (state) => state.port?.close(),
|
|
715
|
+
process: async ({ value }, options, context) => {
|
|
716
|
+
if (!process2) throw new Error("Worker does not support atomic processing");
|
|
717
|
+
return { value: await process2(value, options, createContext(context), context.state.context) };
|
|
718
|
+
},
|
|
719
|
+
...processInBatches2 ? {
|
|
720
|
+
processInBatches: async function* (inputs, options, context) {
|
|
721
|
+
async function* values() {
|
|
722
|
+
for await (const input of inputs) yield input.value;
|
|
723
|
+
}
|
|
724
|
+
for await (const value of processInBatches2(
|
|
725
|
+
values(),
|
|
726
|
+
options,
|
|
727
|
+
createContext(context),
|
|
728
|
+
context.state.context
|
|
729
|
+
)) {
|
|
730
|
+
yield { value };
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
} : {}
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
function createContext(context) {
|
|
737
|
+
let requestIdentifier = 0;
|
|
738
|
+
const port = context.state.port;
|
|
739
|
+
return {
|
|
740
|
+
signal: context.signal,
|
|
741
|
+
throwIfAborted: () => context.throwIfAborted(),
|
|
742
|
+
reportProgress: (progress) => context.reportProgress(normalizeTaskProgress(progress)),
|
|
743
|
+
process: port ? (input, options = {}, jobContext = {}) => {
|
|
744
|
+
context.throwIfAborted();
|
|
745
|
+
const identifier = ++requestIdentifier;
|
|
746
|
+
return new Promise((resolve, reject) => {
|
|
747
|
+
const onMessage = (event) => {
|
|
748
|
+
if (event.data.identifier !== identifier) return;
|
|
749
|
+
cleanup();
|
|
750
|
+
if (event.data.error) {
|
|
751
|
+
const error = new Error(event.data.error.message);
|
|
752
|
+
error.name = event.data.error.name;
|
|
753
|
+
reject(error);
|
|
754
|
+
} else resolve(event.data.value);
|
|
755
|
+
};
|
|
756
|
+
const onAbort = () => {
|
|
757
|
+
cleanup();
|
|
758
|
+
reject(context.signal.reason);
|
|
759
|
+
};
|
|
760
|
+
const cleanup = () => {
|
|
761
|
+
port.removeEventListener("message", onMessage);
|
|
762
|
+
context.signal.removeEventListener("abort", onAbort);
|
|
763
|
+
};
|
|
764
|
+
port.addEventListener("message", onMessage);
|
|
765
|
+
context.signal.addEventListener("abort", onAbort, { once: true });
|
|
766
|
+
port.start();
|
|
767
|
+
try {
|
|
768
|
+
const request = { identifier, input, options, context: jobContext };
|
|
769
|
+
port.postMessage(request, getTransferList2(request));
|
|
770
|
+
} catch (error) {
|
|
771
|
+
cleanup();
|
|
772
|
+
reject(error);
|
|
773
|
+
}
|
|
774
|
+
});
|
|
775
|
+
} : void 0
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
|
|
346
779
|
// src/worker-utils/workers/null-worker.ts
|
|
347
|
-
|
|
780
|
+
createWorker2(
|
|
348
781
|
async (data) => {
|
|
349
782
|
return data;
|
|
350
783
|
},
|