@loaders.gl/core 5.0.0-alpha.13 → 5.0.0-alpha.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.dev.js +190 -63
- package/dist/dist.min.js +3 -3
- package/dist/index.cjs +205 -72
- package/dist/index.cjs.map +2 -2
- package/dist/lib/api/parse-file.js +2 -0
- package/dist/lib/api/parse-file.js.map +1 -1
- package/dist/lib/api/parse-in-batches.d.ts.map +1 -1
- package/dist/lib/api/parse-in-batches.js +5 -4
- package/dist/lib/api/parse-in-batches.js.map +1 -1
- package/dist/lib/api/parse.js +4 -2
- package/dist/lib/api/parse.js.map +1 -1
- package/dist/lib/init.js +1 -1
- package/dist/lib/loader-utils/get-fetch-function.d.ts.map +1 -1
- package/dist/lib/loader-utils/get-fetch-function.js +3 -1
- package/dist/lib/loader-utils/get-fetch-function.js.map +1 -1
- package/dist/lib/loader-utils/loader-context.d.ts.map +1 -1
- package/dist/lib/loader-utils/loader-context.js +4 -0
- package/dist/lib/loader-utils/loader-context.js.map +1 -1
- package/dist/lib/loader-utils/option-defaults.d.ts.map +1 -1
- package/dist/lib/loader-utils/option-defaults.js +1 -0
- package/dist/lib/loader-utils/option-defaults.js.map +1 -1
- package/dist/lib/loader-utils/option-utils.js +1 -1
- package/dist/lib/loader-utils/option-utils.js.map +1 -1
- package/dist/loader-utils/index.cjs +231 -92
- package/dist/loader-utils/index.cjs.map +2 -2
- package/dist/loader-utils/index.d.ts +1 -1
- package/dist/loader-utils/index.d.ts.map +1 -1
- package/dist/loader-utils/index.js +1 -1
- package/dist/loader-utils/index.js.map +1 -1
- package/dist/loader-utils/json-loader.d.ts +1 -1
- package/dist/loader-utils/json-loader.js +2 -2
- package/dist/loader-utils/lib/log-utils/log.js +1 -1
- package/dist/loader-utils/lib/request-utils/request-credentials.d.ts +3 -1
- package/dist/loader-utils/lib/request-utils/request-credentials.d.ts.map +1 -1
- package/dist/loader-utils/lib/request-utils/request-credentials.js +10 -16
- package/dist/loader-utils/lib/request-utils/request-credentials.js.map +1 -1
- package/dist/loader-utils/lib/worker-loader-utils/create-loader-worker.d.ts +3 -0
- package/dist/loader-utils/lib/worker-loader-utils/create-loader-worker.d.ts.map +1 -1
- package/dist/loader-utils/lib/worker-loader-utils/create-loader-worker.js +13 -12
- package/dist/loader-utils/lib/worker-loader-utils/create-loader-worker.js.map +1 -1
- package/dist/loader-utils/lib/worker-loader-utils/parse-with-worker.d.ts +6 -0
- 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 +38 -7
- package/dist/loader-utils/lib/worker-loader-utils/parse-with-worker.js.map +1 -1
- package/dist/loader-utils/loader-types.d.ts +12 -4
- package/dist/loader-utils/loader-types.d.ts.map +1 -1
- package/dist/loader-utils/loader-types.js.map +1 -1
- package/dist/null-loader.js +1 -1
- package/dist/null-worker-node.js +60 -15
- package/dist/null-worker.js +59 -15
- package/dist/schema-utils/lib/table/tables/convert-table.d.ts +1 -1
- package/dist/schema-utils/lib/table/tables/convert-table.js +1 -1
- package/dist/worker-utils/index.cjs +170 -49
- package/dist/worker-utils/index.cjs.map +2 -2
- package/dist/worker-utils/index.d.ts +2 -2
- package/dist/worker-utils/index.d.ts.map +1 -1
- package/dist/worker-utils/index.js +1 -1
- package/dist/worker-utils/index.js.map +1 -1
- package/dist/worker-utils/lib/env-utils/version.js +2 -2
- package/dist/worker-utils/lib/worker-api/create-worker.d.ts.map +1 -1
- package/dist/worker-utils/lib/worker-api/create-worker.js +40 -2
- package/dist/worker-utils/lib/worker-api/create-worker.js.map +1 -1
- package/dist/worker-utils/lib/worker-api/get-worker-url.d.ts +2 -0
- package/dist/worker-utils/lib/worker-api/get-worker-url.d.ts.map +1 -1
- package/dist/worker-utils/lib/worker-api/get-worker-url.js +7 -11
- package/dist/worker-utils/lib/worker-api/get-worker-url.js.map +1 -1
- package/dist/worker-utils/lib/worker-api/process-on-worker.d.ts +6 -0
- 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 +64 -27
- package/dist/worker-utils/lib/worker-api/process-on-worker.js.map +1 -1
- package/dist/worker-utils/lib/worker-farm/worker-job.d.ts.map +1 -1
- package/dist/worker-utils/lib/worker-farm/worker-job.js +3 -2
- package/dist/worker-utils/lib/worker-farm/worker-job.js.map +1 -1
- package/dist/worker-utils/lib/worker-farm/worker-pool.d.ts +1 -1
- package/dist/worker-utils/lib/worker-farm/worker-pool.d.ts.map +1 -1
- package/dist/worker-utils/lib/worker-farm/worker-pool.js +65 -12
- package/dist/worker-utils/lib/worker-farm/worker-pool.js.map +1 -1
- package/dist/worker-utils/null-worker-node.js +36 -2
- package/dist/worker-utils/null-worker-node.js.map +2 -2
- package/dist/worker-utils/null-worker.js +36 -2
- package/dist/worker-utils/null-worker.js.map +2 -2
- package/dist/worker-utils/types.d.ts +25 -4
- package/dist/worker-utils/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/lib/api/parse-file.ts +2 -0
- package/src/lib/api/parse-in-batches.ts +5 -5
- package/src/lib/api/parse.ts +4 -2
- package/src/lib/loader-utils/get-fetch-function.ts +4 -2
- package/src/lib/loader-utils/loader-context.ts +4 -0
- package/src/lib/loader-utils/option-defaults.ts +1 -0
- package/src/lib/loader-utils/option-utils.ts +1 -1
- package/src/loader-utils/index.ts +1 -0
- package/src/loader-utils/json-loader.ts +1 -1
- package/src/loader-utils/lib/request-utils/request-credentials.ts +10 -12
- package/src/loader-utils/lib/worker-loader-utils/create-loader-worker.ts +38 -15
- package/src/loader-utils/lib/worker-loader-utils/parse-with-worker.ts +52 -7
- package/src/loader-utils/loader-types.ts +16 -4
- package/src/schema-utils/lib/table/tables/convert-table.ts +1 -1
- package/src/worker-utils/index.ts +3 -1
- package/src/worker-utils/lib/worker-api/create-worker.ts +41 -2
- package/src/worker-utils/lib/worker-api/get-worker-url.ts +13 -14
- package/src/worker-utils/lib/worker-api/process-on-worker.ts +128 -73
- package/src/worker-utils/lib/worker-farm/worker-job.ts +4 -2
- package/src/worker-utils/lib/worker-farm/worker-pool.ts +65 -12
- package/src/worker-utils/types.ts +26 -3
|
@@ -1 +1 @@
|
|
|
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;
|
|
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,GAAgB,EAAE,CAAC;IAC3B,SAAS,GAAmB,EAAE,CAAC;IAC/B,UAAU,GAAG,IAAI,GAAG,EAAa,CAAC;IAClC,KAAK,GAAG,CAAC,CAAC;IACV,WAAW,GAAG,KAAK,CAAC;IAE5B,uDAAuD;IACvD,MAAM,CAAC,WAAW;QAChB,OAAO,Y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AAC,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"}
|
|
@@ -229,6 +229,8 @@ async function createWorker(process, processInBatches2) {
|
|
|
229
229
|
process: processOnMainThread
|
|
230
230
|
};
|
|
231
231
|
WorkerBody.onmessage = async (type, payload) => {
|
|
232
|
+
const reporter = type === "process" || type === "process-in-batches" ? createProgressReporter() : void 0;
|
|
233
|
+
const jobContext = { ...context, reportProgress: reporter == null ? void 0 : reporter.report };
|
|
232
234
|
try {
|
|
233
235
|
switch (type) {
|
|
234
236
|
case "preload":
|
|
@@ -241,9 +243,10 @@ async function createWorker(process, processInBatches2) {
|
|
|
241
243
|
const result = await process(
|
|
242
244
|
payload.input,
|
|
243
245
|
payload.options || {},
|
|
244
|
-
|
|
246
|
+
jobContext,
|
|
245
247
|
payload.context || {}
|
|
246
248
|
);
|
|
249
|
+
reporter == null ? void 0 : reporter.finish();
|
|
247
250
|
WorkerBody.postMessage("done", { result });
|
|
248
251
|
break;
|
|
249
252
|
case "process-in-batches":
|
|
@@ -258,13 +261,14 @@ async function createWorker(process, processInBatches2) {
|
|
|
258
261
|
const resultIterator = processInBatches2(
|
|
259
262
|
createDemandDrivenIterator(inputBatches),
|
|
260
263
|
payload.options || {},
|
|
261
|
-
|
|
264
|
+
jobContext,
|
|
262
265
|
payload.context || {}
|
|
263
266
|
);
|
|
264
267
|
for await (const batch of resultIterator) {
|
|
265
268
|
await WorkerBody.postMessage("output-batch", { result: batch });
|
|
266
269
|
await outputAcknowledgements.next();
|
|
267
270
|
}
|
|
271
|
+
reporter == null ? void 0 : reporter.finish();
|
|
268
272
|
await WorkerBody.postMessage("done", {});
|
|
269
273
|
} finally {
|
|
270
274
|
activeInputBatches = null;
|
|
@@ -292,6 +296,7 @@ async function createWorker(process, processInBatches2) {
|
|
|
292
296
|
default:
|
|
293
297
|
}
|
|
294
298
|
} catch (error) {
|
|
299
|
+
reporter == null ? void 0 : reporter.finish();
|
|
295
300
|
const message = error instanceof Error ? error.message : "";
|
|
296
301
|
WorkerBody.postMessage("error", { error: message });
|
|
297
302
|
}
|
|
@@ -331,6 +336,35 @@ function processOnMainThread(arrayBuffer, options = {}, jobContext = {}) {
|
|
|
331
336
|
WorkerBody.postMessage("process", payload);
|
|
332
337
|
});
|
|
333
338
|
}
|
|
339
|
+
function createProgressReporter() {
|
|
340
|
+
let pending;
|
|
341
|
+
let finished = false;
|
|
342
|
+
let scheduled = false;
|
|
343
|
+
const flush = () => {
|
|
344
|
+
scheduled = false;
|
|
345
|
+
if (pending) {
|
|
346
|
+
WorkerBody.postMessage("progress", { progress: pending });
|
|
347
|
+
pending = void 0;
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
return {
|
|
351
|
+
/** Records progress while retaining phase transitions. */
|
|
352
|
+
report(progress) {
|
|
353
|
+
if (finished) return;
|
|
354
|
+
if (pending && pending.phase !== progress.phase) flush();
|
|
355
|
+
pending = { ...progress };
|
|
356
|
+
if (!scheduled) {
|
|
357
|
+
scheduled = true;
|
|
358
|
+
setTimeout(flush, 0);
|
|
359
|
+
}
|
|
360
|
+
},
|
|
361
|
+
/** Flushes final progress and suppresses reports from stale callbacks. */
|
|
362
|
+
finish() {
|
|
363
|
+
flush();
|
|
364
|
+
finished = true;
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
}
|
|
334
368
|
|
|
335
369
|
// src/worker-utils/workers/null-worker.ts
|
|
336
370
|
createWorker(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/worker-utils/lib/async-queue/async-queue.ts", "../../src/worker-utils/lib/worker-utils/get-transfer-list.ts", "../../src/worker-utils/lib/node/worker_threads.ts", "../../src/worker-utils/lib/worker-farm/worker-body.ts", "../../src/worker-utils/lib/worker-api/create-worker.ts", "../../src/worker-utils/workers/null-worker.ts"],
|
|
4
|
-
"sourcesContent": ["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\n// From https://github.com/rauschma/async-iter-demo/tree/master/src under MIT license\n// http://2ality.com/2016/10/asynchronous-iteration.html\n\n/**\n * Async Queue\n * - AsyncIterable: An async iterator can be\n * - Values can be pushed onto the queue\n * @example\n * const asyncQueue = new AsyncQueue();\n * setTimeout(() => asyncQueue.enqueue('tick'), 1000);\n * setTimeout(() => asyncQueue.enqueue(new Error('done')), 10000);\n * for await (const value of asyncQueue) {\n * console.log(value); // tick\n * }\n */\nexport default class AsyncQueue<T> {\n private _values: any[];\n private _settlers: any[];\n private _closed: boolean;\n\n constructor() {\n this._values = []; // enqueues > dequeues\n this._settlers = []; // dequeues > enqueues\n this._closed = false;\n }\n\n /** Return an async iterator for this queue */\n [Symbol.asyncIterator](): AsyncIterator<T> {\n return this;\n }\n\n /** Push a new value - the async iterator will yield a promise resolved to this value */\n push(value: T): void {\n return this.enqueue(value);\n }\n\n /**\n * Push a new value - the async iterator will yield a promise resolved to this value\n * Add an error - the async iterator will yield a promise rejected with this value\n */\n enqueue(value: T | Error): void {\n if (this._closed) {\n throw new Error('Closed');\n }\n\n if (this._settlers.length > 0) {\n if (this._values.length > 0) {\n throw new Error('Illegal internal state');\n }\n const settler = this._settlers.shift();\n if (value instanceof Error) {\n settler.reject(value);\n } else {\n settler.resolve({value});\n }\n } else {\n this._values.push(value);\n }\n }\n\n /** Indicate that we not waiting for more values - The async iterator will be done */\n close(): void {\n while (this._settlers.length > 0) {\n const settler = this._settlers.shift();\n settler.resolve({done: true});\n }\n this._closed = true;\n }\n\n // ITERATOR IMPLEMENTATION\n\n /** @returns a Promise for an IteratorResult */\n next(): Promise<IteratorResult<T, any>> {\n // If values in queue, yield the first value\n if (this._values.length > 0) {\n const value = this._values.shift();\n if (value instanceof Error) {\n return Promise.reject(value);\n }\n return Promise.resolve({done: false, value});\n }\n\n // If queue is closed, the iterator is done\n if (this._closed) {\n if (this._settlers.length > 0) {\n throw new Error('Illegal internal state');\n }\n return Promise.resolve({done: true, value: undefined});\n }\n\n // Yield a promise that waits for new values to be enqueued\n return new Promise((resolve, reject) => {\n this._settlers.push({resolve, reject});\n });\n }\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\n// NOTE - there is a copy of this function is both in core and loader-utils\n// core does not need all the utils in loader-utils, just this one.\n\n/**\n * Returns an array of Transferrable objects that can be used with postMessage\n * https://developer.mozilla.org/en-US/docs/Web/API/Worker/postMessage\n * @param object data to be sent via postMessage\n * @param recursive - not for application use\n * @param transfers - not for application use\n * @returns a transfer list that can be passed to postMessage\n */\nexport function getTransferList(\n object: any,\n recursive: boolean = true,\n transfers?: Set<any>\n): Transferable[] {\n // Make sure that items in the transfer list is unique\n const transfersSet = transfers || new Set();\n\n if (!object) {\n // ignore\n } else if (isTransferable(object)) {\n transfersSet.add(object);\n } else if (isTransferable(object.buffer)) {\n // Typed array\n transfersSet.add(object.buffer);\n } else if (ArrayBuffer.isView(object)) {\n // object is a TypeArray viewing into a SharedArrayBuffer (not transferable)\n // Do not iterate through the content in this case\n } else if (recursive && typeof object === 'object') {\n for (const key in object) {\n // Avoid perf hit - only go one level deep\n getTransferList(object[key], recursive, transfersSet);\n }\n }\n\n // If transfers is defined, is internal recursive call\n // Otherwise it's called by the user\n return transfers === undefined ? Array.from(transfersSet) : [];\n}\n\n// https://developer.mozilla.org/en-US/docs/Web/API/Transferable\nfunction isTransferable(object: unknown) {\n if (!object) {\n return false;\n }\n if (object instanceof ArrayBuffer) {\n return true;\n }\n if (typeof MessagePort !== 'undefined' && object instanceof MessagePort) {\n return true;\n }\n if (typeof ImageBitmap !== 'undefined' && object instanceof ImageBitmap) {\n return true;\n }\n // @ts-ignore\n if (typeof OffscreenCanvas !== 'undefined' && object instanceof OffscreenCanvas) {\n return true;\n }\n return false;\n}\n\n/**\n * Recursively drop non serializable values like functions and regexps.\n * @param object\n */\nexport function getTransferListForWriter(object: object | null): object {\n if (object === null) {\n return {};\n }\n const clone = Object.assign({}, object);\n\n Object.keys(clone).forEach(key => {\n // Typed Arrays and Arrays are passed with no change\n if (\n typeof object[key] === 'object' &&\n !ArrayBuffer.isView(object[key]) &&\n !(object[key] instanceof Array)\n ) {\n clone[key] = getTransferListForWriter(object[key]);\n } else if (typeof clone[key] === 'function' || clone[key] instanceof RegExp) {\n clone[key] = {};\n } else {\n clone[key] = object[key];\n }\n });\n\n return clone;\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport * as WorkerThreads from 'worker_threads';\nexport {\n markAsUntransferable,\n isMarkedAsUntransferable,\n markAsUncloneable,\n moveMessagePortToContext,\n receiveMessageOnPort,\n getEnvironmentData,\n setEnvironmentData,\n postMessageToThread,\n isMainThread,\n resourceLimits,\n SHARE_ENV,\n threadId,\n workerData,\n Worker,\n BroadcastChannel,\n MessageChannel,\n MessagePort\n} from 'worker_threads';\nexport type {\n WorkerPerformance,\n TransferListItem,\n WorkerOptions,\n ResourceLimits,\n WorkerEventMap,\n Serializable,\n LockMode,\n Transferable,\n LockGrantedCallback,\n LockInfo,\n LockManagerSnapshot,\n LockOptions,\n StructuredSerializeOptions,\n BroadcastChannelEventMap,\n Lock,\n LockManager,\n MessagePortEventMap\n} from 'worker_threads';\nexport const parentPort = WorkerThreads?.parentPort;\nexport const NodeWorker = WorkerThreads.Worker;\nexport type NodeWorkerType = WorkerThreads.Worker;\n\n/** Optional Node.js worker API, available on runtimes that provide it. */\nexport const isInternalThread = WorkerThreads.isInternalThread;\n\n/** Optional Node.js worker API, available on runtimes that provide it. */\nexport const threadName = WorkerThreads.threadName;\n\n/** Optional Node.js worker API, available on runtimes that provide it. */\nexport const locks = WorkerThreads.locks;\n\n/** Optional Node.js worker API, available on runtimes that provide it. */\nexport const structuredClone = WorkerThreads.structuredClone;\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {WorkerMessageData, WorkerMessageType, WorkerMessagePayload} from '../../types';\nimport {getTransferList} from '../worker-utils/get-transfer-list';\n// import type {TransferListItem} from '../node/worker_threads';\nimport {parentPort} from '../node/worker_threads';\n\ntype TransferListItem = any;\ntype WorkerMessageEvent = MessageEvent<WorkerMessageData> | WorkerMessageData;\ntype WorkerMessageListener = (type: WorkerMessageType, payload: WorkerMessagePayload) => any;\n\n/** Vile hack to defeat over-zealous bundlers from stripping out the require */\nasync function getParentPort() {\n // const isNode = globalThis.process;\n // let parentPort;\n // try {\n // // biome-ignore format: preserve intentional fixture layout\n // eval('globalThis.parentPort = require(\\'worker_threads\\').parentPort'); // eslint-disable-line no-eval\n // parentPort = globalThis.parentPort;\n // } catch {\n // try {\n // // biome-ignore format: preserve intentional fixture layout\n // eval('globalThis.workerThreadsPromise = import(\\'worker_threads\\')'); // eslint-disable-line no-eval\n // const workerThreads = await globalThis.workerThreadsPromise;\n // parentPort = workerThreads.parentPort;\n // } catch (error) {\n // console.error((error as Error).message); // eslint-disable-line no-console\n // }\n // }\n return parentPort;\n}\n\nconst onMessageWrapperMap = new Map<WorkerMessageListener, (message: WorkerMessageEvent) => void>();\n\n/**\n * Type safe wrapper for worker code\n */\nexport default class WorkerBody {\n /** Check that we are actually in a worker thread */\n static async inWorkerThread(): Promise<boolean> {\n return typeof self !== 'undefined' || Boolean(await getParentPort());\n }\n\n /*\n * (type: WorkerMessageType, payload: WorkerMessagePayload) => any\n */\n static set onmessage(onMessage: (type: WorkerMessageType, payload: WorkerMessagePayload) => any) {\n async function handleMessage(message) {\n const parentPort = await getParentPort();\n // Confusingly the message itself also has a 'type' field which is always set to 'message'\n const {type, payload} = parentPort ? message : message.data;\n // if (!isKnownMessage(message)) {\n // return;\n // }\n onMessage(type, payload);\n }\n\n getParentPort().then(parentPort => {\n if (parentPort) {\n parentPort.on('message', message => {\n handleMessage(message);\n });\n // if (message == 'exit') { parentPort.unref(); }\n // eslint-disable-next-line\n parentPort.on('exit', () => console.debug('Node worker closing'));\n } else {\n // eslint-disable-next-line no-restricted-globals\n globalThis.onmessage = handleMessage;\n }\n });\n }\n\n static async addEventListener(onMessage: WorkerMessageListener) {\n let onMessageWrapper = onMessageWrapperMap.get(onMessage);\n\n if (!onMessageWrapper) {\n onMessageWrapper = (message: WorkerMessageEvent) => {\n const messageData = getWorkerMessageData(message);\n if (!messageData) {\n return;\n }\n onMessage(messageData.type, messageData.payload);\n };\n onMessageWrapperMap.set(onMessage, onMessageWrapper);\n }\n\n const parentPort = await getParentPort();\n if (parentPort) {\n parentPort.on('message', onMessageWrapper);\n } else {\n globalThis.addEventListener('message', onMessageWrapper);\n }\n }\n\n static async removeEventListener(onMessage: WorkerMessageListener) {\n const onMessageWrapper = onMessageWrapperMap.get(onMessage);\n onMessageWrapperMap.delete(onMessage);\n if (!onMessageWrapper) {\n return;\n }\n const parentPort = await getParentPort();\n if (parentPort) {\n parentPort.off('message', onMessageWrapper);\n } else {\n globalThis.removeEventListener('message', onMessageWrapper);\n }\n }\n\n /**\n * Send a message from a worker to creating thread (main thread)\n * @param type\n * @param payload\n */\n static async postMessage(type: WorkerMessageType, payload: WorkerMessagePayload): Promise<void> {\n const data: WorkerMessageData = {source: 'loaders.gl', type, payload};\n // console.log('posting message', data);\n\n // Cast to Node compatible transfer list\n const transferList = getTransferList(payload) as TransferListItem[];\n\n const parentPort = await getParentPort();\n if (parentPort) {\n parentPort.postMessage(data, transferList);\n // console.log('posted message', data);\n } else {\n // @ts-expect-error Outside of worker scopes this call has a third parameter\n globalThis.postMessage(data, transferList);\n }\n }\n}\n\n// Filter out noise messages sent to workers\nfunction getWorkerMessageData(message: WorkerMessageEvent): WorkerMessageData | null {\n if (!message || typeof message !== 'object') {\n return null;\n }\n const messageData = 'data' in message && message.type === 'message' ? message.data : message;\n return messageData &&\n typeof messageData.source === 'string' &&\n messageData.source.startsWith('loaders.gl')\n ? messageData\n : null;\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {\n WorkerMessageType,\n WorkerMessagePayload,\n WorkerContext,\n WorkerJobContext,\n Process,\n ProcessInBatches\n} from '../../types';\nimport AsyncQueue from '../async-queue/async-queue';\nimport WorkerBody from '../worker-farm/worker-body';\n// import {validateWorkerVersion} from './validate-worker-version';\n\n/** Counter for jobs */\nlet requestId = 0;\nlet activeInputBatches: AsyncQueue<any> | null = null;\nlet activeOutputAcknowledgements: AsyncQueue<void> | null = null;\n\nexport type ProcessOnMainThread = (\n data: any,\n options?: {[key: string]: any},\n jobContext?: WorkerJobContext\n) => any;\n\n/**\n * Set up a WebWorkerGlobalScope to talk with the main thread\n */\nexport async function createWorker(\n process: Process,\n processInBatches?: ProcessInBatches\n): Promise<void> {\n if (!(await WorkerBody.inWorkerThread())) {\n return;\n }\n\n const context: WorkerContext = {\n process: processOnMainThread\n };\n\n // eslint-disable-next-line complexity\n WorkerBody.onmessage = async (type: WorkerMessageType, payload: WorkerMessagePayload) => {\n try {\n switch (type) {\n case 'preload':\n WorkerBody.postMessage('done', {});\n break;\n\n case 'process':\n if (!process) {\n throw new Error('Worker does not support atomic processing');\n }\n const result = await process(\n payload.input,\n payload.options || {},\n context,\n payload.context || {}\n );\n WorkerBody.postMessage('done', {result});\n break;\n\n case 'process-in-batches':\n if (!processInBatches) {\n throw new Error('Worker does not support batched processing');\n }\n const inputBatches = new AsyncQueue<any>();\n const outputAcknowledgements = new AsyncQueue<void>();\n activeInputBatches = inputBatches;\n activeOutputAcknowledgements = outputAcknowledgements;\n try {\n const resultIterator = processInBatches(\n createDemandDrivenIterator(inputBatches),\n payload.options || {},\n context,\n payload.context || {}\n );\n for await (const batch of resultIterator) {\n await WorkerBody.postMessage('output-batch', {result: batch});\n await outputAcknowledgements.next();\n }\n await WorkerBody.postMessage('done', {});\n } finally {\n activeInputBatches = null;\n activeOutputAcknowledgements = null;\n }\n break;\n\n case 'input-batch':\n if (!activeInputBatches) {\n throw new Error('Worker has no active batched processing session');\n }\n activeInputBatches.push(payload.input);\n break;\n\n case 'input-done':\n if (!activeInputBatches) {\n throw new Error('Worker has no active batched processing session');\n }\n activeInputBatches.close();\n break;\n\n case 'output-ack':\n if (!activeOutputAcknowledgements) {\n throw new Error('Worker has no active batched processing session');\n }\n activeOutputAcknowledgements.push(undefined);\n break;\n\n default:\n }\n } catch (error) {\n const message = error instanceof Error ? error.message : '';\n WorkerBody.postMessage('error', {error: message});\n }\n };\n}\n\n/** Requests exactly one input batch whenever the worker-side processor advances its iterator. */\nasync function* createDemandDrivenIterator(inputBatches: AsyncQueue<any>): AsyncIterable<any> {\n while (true) {\n await WorkerBody.postMessage('input-request', {});\n const nextBatch = await inputBatches.next();\n if (nextBatch.done) {\n return;\n }\n yield nextBatch.value;\n }\n}\n\nfunction processOnMainThread(arrayBuffer: ArrayBuffer, options = {}, jobContext = {}) {\n return new Promise((resolve, reject) => {\n const id = requestId++;\n\n /**\n */\n const onMessage = (type: string, payload: WorkerMessagePayload) => {\n if (payload.id !== id) {\n // not ours\n return;\n }\n\n switch (type) {\n case 'done':\n WorkerBody.removeEventListener(onMessage);\n resolve(payload.result);\n break;\n\n case 'error':\n WorkerBody.removeEventListener(onMessage);\n reject(payload.error);\n break;\n\n default:\n // ignore\n }\n };\n\n WorkerBody.addEventListener(onMessage);\n\n // Ask the main thread to decode data\n const payload = {id, input: arrayBuffer, options, context: jobContext};\n WorkerBody.postMessage('process', payload);\n });\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport {createWorker} from '../lib/worker-api/create-worker';\n\ncreateWorker(\n async data => {\n // @ts-ignore\n return data;\n },\n /** Echoes batches together with session-local state for worker protocol tests. */\n async function* processInBatches(iterator) {\n let batchIndex = 0;\n for await (const input of iterator) {\n yield {input, batchIndex};\n batchIndex++;\n }\n }\n);\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAmBA,IAAqB,aAArB,MAAmC;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AAAA,EAER,cAAc;AACZ,SAAK,UAAU,CAAC;AAChB,SAAK,YAAY,CAAC;AAClB,SAAK,UAAU;AAAA,EACjB;AAAA;AAAA,EAGA,CAAC,OAAO,aAAa,IAAsB;AACzC,WAAO;AAAA,EACT;AAAA;AAAA,EAGA,KAAK,OAAgB;AACnB,WAAO,KAAK,QAAQ,KAAK;AAAA,EAC3B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,QAAQ,OAAwB;AAC9B,QAAI,KAAK,SAAS;AAChB,YAAM,IAAI,MAAM,QAAQ;AAAA,IAC1B;AAEA,QAAI,KAAK,UAAU,SAAS,GAAG;AAC7B,UAAI,KAAK,QAAQ,SAAS,GAAG;AAC3B,cAAM,IAAI,MAAM,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AAW,OAAO,YAAY,UAAU;AAC3C,WAAO;AAAA,EACT;AACA,QAAM,cAAc,UAAU,WAAW,QAAQ,SAAS,YAAY,QAAQ,OAAO;AACrF,SAAO,eACL,OAAO,YAAY,WAAW,YAC9B,YAAY,OAAO,WAAW,YAAY,IACxC,cACA;AACN;;;
|
|
4
|
+
"sourcesContent": ["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\n// From https://github.com/rauschma/async-iter-demo/tree/master/src under MIT license\n// http://2ality.com/2016/10/asynchronous-iteration.html\n\n/**\n * Async Queue\n * - AsyncIterable: An async iterator can be\n * - Values can be pushed onto the queue\n * @example\n * const asyncQueue = new AsyncQueue();\n * setTimeout(() => asyncQueue.enqueue('tick'), 1000);\n * setTimeout(() => asyncQueue.enqueue(new Error('done')), 10000);\n * for await (const value of asyncQueue) {\n * console.log(value); // tick\n * }\n */\nexport default class AsyncQueue<T> {\n private _values: any[];\n private _settlers: any[];\n private _closed: boolean;\n\n constructor() {\n this._values = []; // enqueues > dequeues\n this._settlers = []; // dequeues > enqueues\n this._closed = false;\n }\n\n /** Return an async iterator for this queue */\n [Symbol.asyncIterator](): AsyncIterator<T> {\n return this;\n }\n\n /** Push a new value - the async iterator will yield a promise resolved to this value */\n push(value: T): void {\n return this.enqueue(value);\n }\n\n /**\n * Push a new value - the async iterator will yield a promise resolved to this value\n * Add an error - the async iterator will yield a promise rejected with this value\n */\n enqueue(value: T | Error): void {\n if (this._closed) {\n throw new Error('Closed');\n }\n\n if (this._settlers.length > 0) {\n if (this._values.length > 0) {\n throw new Error('Illegal internal state');\n }\n const settler = this._settlers.shift();\n if (value instanceof Error) {\n settler.reject(value);\n } else {\n settler.resolve({value});\n }\n } else {\n this._values.push(value);\n }\n }\n\n /** Indicate that we not waiting for more values - The async iterator will be done */\n close(): void {\n while (this._settlers.length > 0) {\n const settler = this._settlers.shift();\n settler.resolve({done: true});\n }\n this._closed = true;\n }\n\n // ITERATOR IMPLEMENTATION\n\n /** @returns a Promise for an IteratorResult */\n next(): Promise<IteratorResult<T, any>> {\n // If values in queue, yield the first value\n if (this._values.length > 0) {\n const value = this._values.shift();\n if (value instanceof Error) {\n return Promise.reject(value);\n }\n return Promise.resolve({done: false, value});\n }\n\n // If queue is closed, the iterator is done\n if (this._closed) {\n if (this._settlers.length > 0) {\n throw new Error('Illegal internal state');\n }\n return Promise.resolve({done: true, value: undefined});\n }\n\n // Yield a promise that waits for new values to be enqueued\n return new Promise((resolve, reject) => {\n this._settlers.push({resolve, reject});\n });\n }\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\n// NOTE - there is a copy of this function is both in core and loader-utils\n// core does not need all the utils in loader-utils, just this one.\n\n/**\n * Returns an array of Transferrable objects that can be used with postMessage\n * https://developer.mozilla.org/en-US/docs/Web/API/Worker/postMessage\n * @param object data to be sent via postMessage\n * @param recursive - not for application use\n * @param transfers - not for application use\n * @returns a transfer list that can be passed to postMessage\n */\nexport function getTransferList(\n object: any,\n recursive: boolean = true,\n transfers?: Set<any>\n): Transferable[] {\n // Make sure that items in the transfer list is unique\n const transfersSet = transfers || new Set();\n\n if (!object) {\n // ignore\n } else if (isTransferable(object)) {\n transfersSet.add(object);\n } else if (isTransferable(object.buffer)) {\n // Typed array\n transfersSet.add(object.buffer);\n } else if (ArrayBuffer.isView(object)) {\n // object is a TypeArray viewing into a SharedArrayBuffer (not transferable)\n // Do not iterate through the content in this case\n } else if (recursive && typeof object === 'object') {\n for (const key in object) {\n // Avoid perf hit - only go one level deep\n getTransferList(object[key], recursive, transfersSet);\n }\n }\n\n // If transfers is defined, is internal recursive call\n // Otherwise it's called by the user\n return transfers === undefined ? Array.from(transfersSet) : [];\n}\n\n// https://developer.mozilla.org/en-US/docs/Web/API/Transferable\nfunction isTransferable(object: unknown) {\n if (!object) {\n return false;\n }\n if (object instanceof ArrayBuffer) {\n return true;\n }\n if (typeof MessagePort !== 'undefined' && object instanceof MessagePort) {\n return true;\n }\n if (typeof ImageBitmap !== 'undefined' && object instanceof ImageBitmap) {\n return true;\n }\n // @ts-ignore\n if (typeof OffscreenCanvas !== 'undefined' && object instanceof OffscreenCanvas) {\n return true;\n }\n return false;\n}\n\n/**\n * Recursively drop non serializable values like functions and regexps.\n * @param object\n */\nexport function getTransferListForWriter(object: object | null): object {\n if (object === null) {\n return {};\n }\n const clone = Object.assign({}, object);\n\n Object.keys(clone).forEach(key => {\n // Typed Arrays and Arrays are passed with no change\n if (\n typeof object[key] === 'object' &&\n !ArrayBuffer.isView(object[key]) &&\n !(object[key] instanceof Array)\n ) {\n clone[key] = getTransferListForWriter(object[key]);\n } else if (typeof clone[key] === 'function' || clone[key] instanceof RegExp) {\n clone[key] = {};\n } else {\n clone[key] = object[key];\n }\n });\n\n return clone;\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport * as WorkerThreads from 'worker_threads';\nexport {\n markAsUntransferable,\n isMarkedAsUntransferable,\n markAsUncloneable,\n moveMessagePortToContext,\n receiveMessageOnPort,\n getEnvironmentData,\n setEnvironmentData,\n postMessageToThread,\n isMainThread,\n resourceLimits,\n SHARE_ENV,\n threadId,\n workerData,\n Worker,\n BroadcastChannel,\n MessageChannel,\n MessagePort\n} from 'worker_threads';\nexport type {\n WorkerPerformance,\n TransferListItem,\n WorkerOptions,\n ResourceLimits,\n WorkerEventMap,\n Serializable,\n LockMode,\n Transferable,\n LockGrantedCallback,\n LockInfo,\n LockManagerSnapshot,\n LockOptions,\n StructuredSerializeOptions,\n BroadcastChannelEventMap,\n Lock,\n LockManager,\n MessagePortEventMap\n} from 'worker_threads';\nexport const parentPort = WorkerThreads?.parentPort;\nexport const NodeWorker = WorkerThreads.Worker;\nexport type NodeWorkerType = WorkerThreads.Worker;\n\n/** Optional Node.js worker API, available on runtimes that provide it. */\nexport const isInternalThread = WorkerThreads.isInternalThread;\n\n/** Optional Node.js worker API, available on runtimes that provide it. */\nexport const threadName = WorkerThreads.threadName;\n\n/** Optional Node.js worker API, available on runtimes that provide it. */\nexport const locks = WorkerThreads.locks;\n\n/** Optional Node.js worker API, available on runtimes that provide it. */\nexport const structuredClone = WorkerThreads.structuredClone;\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {WorkerMessageData, WorkerMessageType, WorkerMessagePayload} from '../../types';\nimport {getTransferList} from '../worker-utils/get-transfer-list';\n// import type {TransferListItem} from '../node/worker_threads';\nimport {parentPort} from '../node/worker_threads';\n\ntype TransferListItem = any;\ntype WorkerMessageEvent = MessageEvent<WorkerMessageData> | WorkerMessageData;\ntype WorkerMessageListener = (type: WorkerMessageType, payload: WorkerMessagePayload) => any;\n\n/** Vile hack to defeat over-zealous bundlers from stripping out the require */\nasync function getParentPort() {\n // const isNode = globalThis.process;\n // let parentPort;\n // try {\n // // biome-ignore format: preserve intentional fixture layout\n // eval('globalThis.parentPort = require(\\'worker_threads\\').parentPort'); // eslint-disable-line no-eval\n // parentPort = globalThis.parentPort;\n // } catch {\n // try {\n // // biome-ignore format: preserve intentional fixture layout\n // eval('globalThis.workerThreadsPromise = import(\\'worker_threads\\')'); // eslint-disable-line no-eval\n // const workerThreads = await globalThis.workerThreadsPromise;\n // parentPort = workerThreads.parentPort;\n // } catch (error) {\n // console.error((error as Error).message); // eslint-disable-line no-console\n // }\n // }\n return parentPort;\n}\n\nconst onMessageWrapperMap = new Map<WorkerMessageListener, (message: WorkerMessageEvent) => void>();\n\n/**\n * Type safe wrapper for worker code\n */\nexport default class WorkerBody {\n /** Check that we are actually in a worker thread */\n static async inWorkerThread(): Promise<boolean> {\n return typeof self !== 'undefined' || Boolean(await getParentPort());\n }\n\n /*\n * (type: WorkerMessageType, payload: WorkerMessagePayload) => any\n */\n static set onmessage(onMessage: (type: WorkerMessageType, payload: WorkerMessagePayload) => any) {\n async function handleMessage(message) {\n const parentPort = await getParentPort();\n // Confusingly the message itself also has a 'type' field which is always set to 'message'\n const {type, payload} = parentPort ? message : message.data;\n // if (!isKnownMessage(message)) {\n // return;\n // }\n onMessage(type, payload);\n }\n\n getParentPort().then(parentPort => {\n if (parentPort) {\n parentPort.on('message', message => {\n handleMessage(message);\n });\n // if (message == 'exit') { parentPort.unref(); }\n // eslint-disable-next-line\n parentPort.on('exit', () => console.debug('Node worker closing'));\n } else {\n // eslint-disable-next-line no-restricted-globals\n globalThis.onmessage = handleMessage;\n }\n });\n }\n\n static async addEventListener(onMessage: WorkerMessageListener) {\n let onMessageWrapper = onMessageWrapperMap.get(onMessage);\n\n if (!onMessageWrapper) {\n onMessageWrapper = (message: WorkerMessageEvent) => {\n const messageData = getWorkerMessageData(message);\n if (!messageData) {\n return;\n }\n onMessage(messageData.type, messageData.payload);\n };\n onMessageWrapperMap.set(onMessage, onMessageWrapper);\n }\n\n const parentPort = await getParentPort();\n if (parentPort) {\n parentPort.on('message', onMessageWrapper);\n } else {\n globalThis.addEventListener('message', onMessageWrapper);\n }\n }\n\n static async removeEventListener(onMessage: WorkerMessageListener) {\n const onMessageWrapper = onMessageWrapperMap.get(onMessage);\n onMessageWrapperMap.delete(onMessage);\n if (!onMessageWrapper) {\n return;\n }\n const parentPort = await getParentPort();\n if (parentPort) {\n parentPort.off('message', onMessageWrapper);\n } else {\n globalThis.removeEventListener('message', onMessageWrapper);\n }\n }\n\n /**\n * Send a message from a worker to creating thread (main thread)\n * @param type\n * @param payload\n */\n static async postMessage(type: WorkerMessageType, payload: WorkerMessagePayload): Promise<void> {\n const data: WorkerMessageData = {source: 'loaders.gl', type, payload};\n // console.log('posting message', data);\n\n // Cast to Node compatible transfer list\n const transferList = getTransferList(payload) as TransferListItem[];\n\n const parentPort = await getParentPort();\n if (parentPort) {\n parentPort.postMessage(data, transferList);\n // console.log('posted message', data);\n } else {\n // @ts-expect-error Outside of worker scopes this call has a third parameter\n globalThis.postMessage(data, transferList);\n }\n }\n}\n\n// Filter out noise messages sent to workers\nfunction getWorkerMessageData(message: WorkerMessageEvent): WorkerMessageData | null {\n if (!message || typeof message !== 'object') {\n return null;\n }\n const messageData = 'data' in message && message.type === 'message' ? message.data : message;\n return messageData &&\n typeof messageData.source === 'string' &&\n messageData.source.startsWith('loaders.gl')\n ? messageData\n : null;\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {\n WorkerProgress,\n WorkerMessageType,\n WorkerMessagePayload,\n WorkerContext,\n WorkerJobContext,\n Process,\n ProcessInBatches\n} from '../../types';\nimport AsyncQueue from '../async-queue/async-queue';\nimport WorkerBody from '../worker-farm/worker-body';\n// import {validateWorkerVersion} from './validate-worker-version';\n\n/** Counter for jobs */\nlet requestId = 0;\nlet activeInputBatches: AsyncQueue<any> | null = null;\nlet activeOutputAcknowledgements: AsyncQueue<void> | null = null;\n\nexport type ProcessOnMainThread = (\n data: any,\n options?: {[key: string]: any},\n jobContext?: WorkerJobContext\n) => any;\n\n/**\n * Set up a WebWorkerGlobalScope to talk with the main thread\n */\nexport async function createWorker(\n process: Process,\n processInBatches?: ProcessInBatches\n): Promise<void> {\n if (!(await WorkerBody.inWorkerThread())) {\n return;\n }\n\n const context: WorkerContext = {\n process: processOnMainThread\n };\n\n // eslint-disable-next-line complexity\n WorkerBody.onmessage = async (type: WorkerMessageType, payload: WorkerMessagePayload) => {\n const reporter =\n type === 'process' || type === 'process-in-batches' ? createProgressReporter() : undefined;\n const jobContext = {...context, reportProgress: reporter?.report};\n try {\n switch (type) {\n case 'preload':\n WorkerBody.postMessage('done', {});\n break;\n\n case 'process':\n if (!process) {\n throw new Error('Worker does not support atomic processing');\n }\n const result = await process(\n payload.input,\n payload.options || {},\n jobContext,\n payload.context || {}\n );\n reporter?.finish();\n WorkerBody.postMessage('done', {result});\n break;\n\n case 'process-in-batches':\n if (!processInBatches) {\n throw new Error('Worker does not support batched processing');\n }\n const inputBatches = new AsyncQueue<any>();\n const outputAcknowledgements = new AsyncQueue<void>();\n activeInputBatches = inputBatches;\n activeOutputAcknowledgements = outputAcknowledgements;\n try {\n const resultIterator = processInBatches(\n createDemandDrivenIterator(inputBatches),\n payload.options || {},\n jobContext,\n payload.context || {}\n );\n for await (const batch of resultIterator) {\n await WorkerBody.postMessage('output-batch', {result: batch});\n await outputAcknowledgements.next();\n }\n reporter?.finish();\n await WorkerBody.postMessage('done', {});\n } finally {\n activeInputBatches = null;\n activeOutputAcknowledgements = null;\n }\n break;\n\n case 'input-batch':\n if (!activeInputBatches) {\n throw new Error('Worker has no active batched processing session');\n }\n activeInputBatches.push(payload.input);\n break;\n\n case 'input-done':\n if (!activeInputBatches) {\n throw new Error('Worker has no active batched processing session');\n }\n activeInputBatches.close();\n break;\n\n case 'output-ack':\n if (!activeOutputAcknowledgements) {\n throw new Error('Worker has no active batched processing session');\n }\n activeOutputAcknowledgements.push(undefined);\n break;\n\n default:\n }\n } catch (error) {\n reporter?.finish();\n const message = error instanceof Error ? error.message : '';\n WorkerBody.postMessage('error', {error: message});\n }\n };\n}\n\n/** Requests exactly one input batch whenever the worker-side processor advances its iterator. */\nasync function* createDemandDrivenIterator(inputBatches: AsyncQueue<any>): AsyncIterable<any> {\n while (true) {\n await WorkerBody.postMessage('input-request', {});\n const nextBatch = await inputBatches.next();\n if (nextBatch.done) {\n return;\n }\n yield nextBatch.value;\n }\n}\n\nfunction processOnMainThread(arrayBuffer: ArrayBuffer, options = {}, jobContext = {}) {\n return new Promise((resolve, reject) => {\n const id = requestId++;\n\n /**\n */\n const onMessage = (type: string, payload: WorkerMessagePayload) => {\n if (payload.id !== id) {\n // not ours\n return;\n }\n\n switch (type) {\n case 'done':\n WorkerBody.removeEventListener(onMessage);\n resolve(payload.result);\n break;\n\n case 'error':\n WorkerBody.removeEventListener(onMessage);\n reject(payload.error);\n break;\n\n default:\n // ignore\n }\n };\n\n WorkerBody.addEventListener(onMessage);\n\n // Ask the main thread to decode data\n const payload = {id, input: arrayBuffer, options, context: jobContext};\n WorkerBody.postMessage('process', payload);\n });\n}\n\n/** Coalesces same-phase reports per event-loop turn and flushes before settlement. */\nfunction createProgressReporter() {\n let pending: WorkerProgress | undefined;\n let finished = false;\n let scheduled = false;\n /** Posts the latest pending measurement. */\n const flush = (): void => {\n scheduled = false;\n if (pending) {\n WorkerBody.postMessage('progress', {progress: pending});\n pending = undefined;\n }\n };\n return {\n /** Records progress while retaining phase transitions. */\n report(progress: WorkerProgress): void {\n if (finished) return;\n if (pending && pending.phase !== progress.phase) flush();\n pending = {...progress};\n if (!scheduled) {\n scheduled = true;\n setTimeout(flush, 0);\n }\n },\n /** Flushes final progress and suppresses reports from stale callbacks. */\n finish(): void {\n flush();\n finished = true;\n }\n };\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport {createWorker} from '../lib/worker-api/create-worker';\n\ncreateWorker(\n async data => {\n // @ts-ignore\n return data;\n },\n /** Echoes batches together with session-local state for worker protocol tests. */\n async function* processInBatches(iterator) {\n let batchIndex = 0;\n for await (const input of iterator) {\n yield {input, batchIndex};\n batchIndex++;\n }\n }\n);\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAmBA,IAAqB,aAArB,MAAmC;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AAAA,EAER,cAAc;AACZ,SAAK,UAAU,CAAC;AAChB,SAAK,YAAY,CAAC;AAClB,SAAK,UAAU;AAAA,EACjB;AAAA;AAAA,EAGA,CAAC,OAAO,aAAa,IAAsB;AACzC,WAAO;AAAA,EACT;AAAA;AAAA,EAGA,KAAK,OAAgB;AACnB,WAAO,KAAK,QAAQ,KAAK;AAAA,EAC3B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,QAAQ,OAAwB;AAC9B,QAAI,KAAK,SAAS;AAChB,YAAM,IAAI,MAAM,QAAQ;AAAA,IAC1B;AAEA,QAAI,KAAK,UAAU,SAAS,GAAG;AAC7B,UAAI,KAAK,QAAQ,SAAS,GAAG;AAC3B,cAAM,IAAI,MAAM,wBAAwB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;AAAA,QACZ,KAAK;AACH,qBAAW,oBAAoB,SAAS;AACxC,kBAAQA,SAAQ,MAAM;AACtB;AAAA,QAEF,KAAK;AACH,qBAAW,oBAAoB,SAAS;AACxC,iBAAOA,SAAQ,KAAK;AACpB;AAAA,QAEF;AAAA,MAEF;AAAA,IACF;AAEA,eAAW,iBAAiB,SAAS;AAGrC,UAAM,UAAU,EAAC,IAAI,OAAO,aAAa,SAAS,SAAS,WAAU;AACrE,eAAW,YAAY,WAAW,OAAO;AAAA,EAC3C,CAAC;AACH;AAGA,SAAS,yBAAyB;AAChC,MAAI;AACJ,MAAI,WAAW;AACf,MAAI,YAAY;AAEhB,QAAM,QAAQ,MAAY;AACxB,gBAAY;AACZ,QAAI,SAAS;AACX,iBAAW,YAAY,YAAY,EAAC,UAAU,QAAO,CAAC;AACtD,gBAAU;AAAA,IACZ;AAAA,EACF;AACA,SAAO;AAAA;AAAA,IAEL,OAAO,UAAgC;AACrC,UAAI,SAAU;AACd,UAAI,WAAW,QAAQ,UAAU,SAAS,MAAO,OAAM;AACvD,gBAAU,EAAC,GAAG,SAAQ;AACtB,UAAI,CAAC,WAAW;AACd,oBAAY;AACZ,mBAAW,OAAO,CAAC;AAAA,MACrB;AAAA,IACF;AAAA;AAAA,IAEA,SAAe;AACb,YAAM;AACN,iBAAW;AAAA,IACb;AAAA,EACF;AACF;;;ACtMA;AAAA,EACE,OAAM,SAAQ;AAEZ,WAAO;AAAA,EACT;AAAA;AAAA,EAEA,gBAAgB,iBAAiB,UAAU;AACzC,QAAI,aAAa;AACjB,qBAAiB,SAAS,UAAU;AAClC,YAAM,EAAC,OAAO,WAAU;AACxB;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
6
|
"names": ["parentPort", "processInBatches", "payload"]
|
|
7
7
|
}
|
|
@@ -206,6 +206,8 @@
|
|
|
206
206
|
process: processOnMainThread
|
|
207
207
|
};
|
|
208
208
|
WorkerBody.onmessage = async (type, payload) => {
|
|
209
|
+
const reporter = type === "process" || type === "process-in-batches" ? createProgressReporter() : void 0;
|
|
210
|
+
const jobContext = { ...context, reportProgress: reporter?.report };
|
|
209
211
|
try {
|
|
210
212
|
switch (type) {
|
|
211
213
|
case "preload":
|
|
@@ -218,9 +220,10 @@
|
|
|
218
220
|
const result = await process(
|
|
219
221
|
payload.input,
|
|
220
222
|
payload.options || {},
|
|
221
|
-
|
|
223
|
+
jobContext,
|
|
222
224
|
payload.context || {}
|
|
223
225
|
);
|
|
226
|
+
reporter?.finish();
|
|
224
227
|
WorkerBody.postMessage("done", { result });
|
|
225
228
|
break;
|
|
226
229
|
case "process-in-batches":
|
|
@@ -235,13 +238,14 @@
|
|
|
235
238
|
const resultIterator = processInBatches2(
|
|
236
239
|
createDemandDrivenIterator(inputBatches),
|
|
237
240
|
payload.options || {},
|
|
238
|
-
|
|
241
|
+
jobContext,
|
|
239
242
|
payload.context || {}
|
|
240
243
|
);
|
|
241
244
|
for await (const batch of resultIterator) {
|
|
242
245
|
await WorkerBody.postMessage("output-batch", { result: batch });
|
|
243
246
|
await outputAcknowledgements.next();
|
|
244
247
|
}
|
|
248
|
+
reporter?.finish();
|
|
245
249
|
await WorkerBody.postMessage("done", {});
|
|
246
250
|
} finally {
|
|
247
251
|
activeInputBatches = null;
|
|
@@ -269,6 +273,7 @@
|
|
|
269
273
|
default:
|
|
270
274
|
}
|
|
271
275
|
} catch (error) {
|
|
276
|
+
reporter?.finish();
|
|
272
277
|
const message = error instanceof Error ? error.message : "";
|
|
273
278
|
WorkerBody.postMessage("error", { error: message });
|
|
274
279
|
}
|
|
@@ -308,6 +313,35 @@
|
|
|
308
313
|
WorkerBody.postMessage("process", payload);
|
|
309
314
|
});
|
|
310
315
|
}
|
|
316
|
+
function createProgressReporter() {
|
|
317
|
+
let pending;
|
|
318
|
+
let finished = false;
|
|
319
|
+
let scheduled = false;
|
|
320
|
+
const flush = () => {
|
|
321
|
+
scheduled = false;
|
|
322
|
+
if (pending) {
|
|
323
|
+
WorkerBody.postMessage("progress", { progress: pending });
|
|
324
|
+
pending = void 0;
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
return {
|
|
328
|
+
/** Records progress while retaining phase transitions. */
|
|
329
|
+
report(progress) {
|
|
330
|
+
if (finished) return;
|
|
331
|
+
if (pending && pending.phase !== progress.phase) flush();
|
|
332
|
+
pending = { ...progress };
|
|
333
|
+
if (!scheduled) {
|
|
334
|
+
scheduled = true;
|
|
335
|
+
setTimeout(flush, 0);
|
|
336
|
+
}
|
|
337
|
+
},
|
|
338
|
+
/** Flushes final progress and suppresses reports from stale callbacks. */
|
|
339
|
+
finish() {
|
|
340
|
+
flush();
|
|
341
|
+
finished = true;
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
}
|
|
311
345
|
|
|
312
346
|
// src/worker-utils/workers/null-worker.ts
|
|
313
347
|
createWorker(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/worker-utils/lib/async-queue/async-queue.ts", "../../src/worker-utils/lib/worker-utils/get-transfer-list.ts", "../../src/worker-utils/lib/node/worker_threads-browser.ts", "../../src/worker-utils/lib/worker-farm/worker-body.ts", "../../src/worker-utils/lib/worker-api/create-worker.ts", "../../src/worker-utils/workers/null-worker.ts"],
|
|
4
|
-
"sourcesContent": ["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\n// From https://github.com/rauschma/async-iter-demo/tree/master/src under MIT license\n// http://2ality.com/2016/10/asynchronous-iteration.html\n\n/**\n * Async Queue\n * - AsyncIterable: An async iterator can be\n * - Values can be pushed onto the queue\n * @example\n * const asyncQueue = new AsyncQueue();\n * setTimeout(() => asyncQueue.enqueue('tick'), 1000);\n * setTimeout(() => asyncQueue.enqueue(new Error('done')), 10000);\n * for await (const value of asyncQueue) {\n * console.log(value); // tick\n * }\n */\nexport default class AsyncQueue<T> {\n private _values: any[];\n private _settlers: any[];\n private _closed: boolean;\n\n constructor() {\n this._values = []; // enqueues > dequeues\n this._settlers = []; // dequeues > enqueues\n this._closed = false;\n }\n\n /** Return an async iterator for this queue */\n [Symbol.asyncIterator](): AsyncIterator<T> {\n return this;\n }\n\n /** Push a new value - the async iterator will yield a promise resolved to this value */\n push(value: T): void {\n return this.enqueue(value);\n }\n\n /**\n * Push a new value - the async iterator will yield a promise resolved to this value\n * Add an error - the async iterator will yield a promise rejected with this value\n */\n enqueue(value: T | Error): void {\n if (this._closed) {\n throw new Error('Closed');\n }\n\n if (this._settlers.length > 0) {\n if (this._values.length > 0) {\n throw new Error('Illegal internal state');\n }\n const settler = this._settlers.shift();\n if (value instanceof Error) {\n settler.reject(value);\n } else {\n settler.resolve({value});\n }\n } else {\n this._values.push(value);\n }\n }\n\n /** Indicate that we not waiting for more values - The async iterator will be done */\n close(): void {\n while (this._settlers.length > 0) {\n const settler = this._settlers.shift();\n settler.resolve({done: true});\n }\n this._closed = true;\n }\n\n // ITERATOR IMPLEMENTATION\n\n /** @returns a Promise for an IteratorResult */\n next(): Promise<IteratorResult<T, any>> {\n // If values in queue, yield the first value\n if (this._values.length > 0) {\n const value = this._values.shift();\n if (value instanceof Error) {\n return Promise.reject(value);\n }\n return Promise.resolve({done: false, value});\n }\n\n // If queue is closed, the iterator is done\n if (this._closed) {\n if (this._settlers.length > 0) {\n throw new Error('Illegal internal state');\n }\n return Promise.resolve({done: true, value: undefined});\n }\n\n // Yield a promise that waits for new values to be enqueued\n return new Promise((resolve, reject) => {\n this._settlers.push({resolve, reject});\n });\n }\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\n// NOTE - there is a copy of this function is both in core and loader-utils\n// core does not need all the utils in loader-utils, just this one.\n\n/**\n * Returns an array of Transferrable objects that can be used with postMessage\n * https://developer.mozilla.org/en-US/docs/Web/API/Worker/postMessage\n * @param object data to be sent via postMessage\n * @param recursive - not for application use\n * @param transfers - not for application use\n * @returns a transfer list that can be passed to postMessage\n */\nexport function getTransferList(\n object: any,\n recursive: boolean = true,\n transfers?: Set<any>\n): Transferable[] {\n // Make sure that items in the transfer list is unique\n const transfersSet = transfers || new Set();\n\n if (!object) {\n // ignore\n } else if (isTransferable(object)) {\n transfersSet.add(object);\n } else if (isTransferable(object.buffer)) {\n // Typed array\n transfersSet.add(object.buffer);\n } else if (ArrayBuffer.isView(object)) {\n // object is a TypeArray viewing into a SharedArrayBuffer (not transferable)\n // Do not iterate through the content in this case\n } else if (recursive && typeof object === 'object') {\n for (const key in object) {\n // Avoid perf hit - only go one level deep\n getTransferList(object[key], recursive, transfersSet);\n }\n }\n\n // If transfers is defined, is internal recursive call\n // Otherwise it's called by the user\n return transfers === undefined ? Array.from(transfersSet) : [];\n}\n\n// https://developer.mozilla.org/en-US/docs/Web/API/Transferable\nfunction isTransferable(object: unknown) {\n if (!object) {\n return false;\n }\n if (object instanceof ArrayBuffer) {\n return true;\n }\n if (typeof MessagePort !== 'undefined' && object instanceof MessagePort) {\n return true;\n }\n if (typeof ImageBitmap !== 'undefined' && object instanceof ImageBitmap) {\n return true;\n }\n // @ts-ignore\n if (typeof OffscreenCanvas !== 'undefined' && object instanceof OffscreenCanvas) {\n return true;\n }\n return false;\n}\n\n/**\n * Recursively drop non serializable values like functions and regexps.\n * @param object\n */\nexport function getTransferListForWriter(object: object | null): object {\n if (object === null) {\n return {};\n }\n const clone = Object.assign({}, object);\n\n Object.keys(clone).forEach(key => {\n // Typed Arrays and Arrays are passed with no change\n if (\n typeof object[key] === 'object' &&\n !ArrayBuffer.isView(object[key]) &&\n !(object[key] instanceof Array)\n ) {\n clone[key] = getTransferListForWriter(object[key]);\n } else if (typeof clone[key] === 'function' || clone[key] instanceof RegExp) {\n clone[key] = {};\n } else {\n clone[key] = object[key];\n }\n });\n\n return clone;\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\n/** Browser polyfill for Node.js built-in `worker_threads` module.\n * These fills are non-functional, and just intended to ensure that\n * `import 'worker_threads` doesn't break browser builds.\n * The replacement is done in package.json browser field\n */\nexport class NodeWorker {\n /** Restores the native worker constructor when this browser shim is embedded in a Node bundle. */\n constructor(...arguments_: unknown[]) {\n const runtimeProcess = (\n globalThis as {\n process?: {\n getBuiltinModule?: (specifier: string) => {\n Worker?: new (...workerArguments: unknown[]) => NodeWorker;\n };\n };\n }\n ).process;\n const WorkerConstructor = runtimeProcess?.getBuiltinModule?.('node:worker_threads').Worker;\n if (WorkerConstructor) {\n return new WorkerConstructor(...arguments_);\n }\n }\n\n /** No-op browser fallback matching the native Worker API. */\n terminate() {}\n}\n\nexport type {NodeWorker as NodeWorkerType};\n\nexport const parentPort = null;\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {WorkerMessageData, WorkerMessageType, WorkerMessagePayload} from '../../types';\nimport {getTransferList} from '../worker-utils/get-transfer-list';\n// import type {TransferListItem} from '../node/worker_threads';\nimport {parentPort} from '../node/worker_threads';\n\ntype TransferListItem = any;\ntype WorkerMessageEvent = MessageEvent<WorkerMessageData> | WorkerMessageData;\ntype WorkerMessageListener = (type: WorkerMessageType, payload: WorkerMessagePayload) => any;\n\n/** Vile hack to defeat over-zealous bundlers from stripping out the require */\nasync function getParentPort() {\n // const isNode = globalThis.process;\n // let parentPort;\n // try {\n // // biome-ignore format: preserve intentional fixture layout\n // eval('globalThis.parentPort = require(\\'worker_threads\\').parentPort'); // eslint-disable-line no-eval\n // parentPort = globalThis.parentPort;\n // } catch {\n // try {\n // // biome-ignore format: preserve intentional fixture layout\n // eval('globalThis.workerThreadsPromise = import(\\'worker_threads\\')'); // eslint-disable-line no-eval\n // const workerThreads = await globalThis.workerThreadsPromise;\n // parentPort = workerThreads.parentPort;\n // } catch (error) {\n // console.error((error as Error).message); // eslint-disable-line no-console\n // }\n // }\n return parentPort;\n}\n\nconst onMessageWrapperMap = new Map<WorkerMessageListener, (message: WorkerMessageEvent) => void>();\n\n/**\n * Type safe wrapper for worker code\n */\nexport default class WorkerBody {\n /** Check that we are actually in a worker thread */\n static async inWorkerThread(): Promise<boolean> {\n return typeof self !== 'undefined' || Boolean(await getParentPort());\n }\n\n /*\n * (type: WorkerMessageType, payload: WorkerMessagePayload) => any\n */\n static set onmessage(onMessage: (type: WorkerMessageType, payload: WorkerMessagePayload) => any) {\n async function handleMessage(message) {\n const parentPort = await getParentPort();\n // Confusingly the message itself also has a 'type' field which is always set to 'message'\n const {type, payload} = parentPort ? message : message.data;\n // if (!isKnownMessage(message)) {\n // return;\n // }\n onMessage(type, payload);\n }\n\n getParentPort().then(parentPort => {\n if (parentPort) {\n parentPort.on('message', message => {\n handleMessage(message);\n });\n // if (message == 'exit') { parentPort.unref(); }\n // eslint-disable-next-line\n parentPort.on('exit', () => console.debug('Node worker closing'));\n } else {\n // eslint-disable-next-line no-restricted-globals\n globalThis.onmessage = handleMessage;\n }\n });\n }\n\n static async addEventListener(onMessage: WorkerMessageListener) {\n let onMessageWrapper = onMessageWrapperMap.get(onMessage);\n\n if (!onMessageWrapper) {\n onMessageWrapper = (message: WorkerMessageEvent) => {\n const messageData = getWorkerMessageData(message);\n if (!messageData) {\n return;\n }\n onMessage(messageData.type, messageData.payload);\n };\n onMessageWrapperMap.set(onMessage, onMessageWrapper);\n }\n\n const parentPort = await getParentPort();\n if (parentPort) {\n parentPort.on('message', onMessageWrapper);\n } else {\n globalThis.addEventListener('message', onMessageWrapper);\n }\n }\n\n static async removeEventListener(onMessage: WorkerMessageListener) {\n const onMessageWrapper = onMessageWrapperMap.get(onMessage);\n onMessageWrapperMap.delete(onMessage);\n if (!onMessageWrapper) {\n return;\n }\n const parentPort = await getParentPort();\n if (parentPort) {\n parentPort.off('message', onMessageWrapper);\n } else {\n globalThis.removeEventListener('message', onMessageWrapper);\n }\n }\n\n /**\n * Send a message from a worker to creating thread (main thread)\n * @param type\n * @param payload\n */\n static async postMessage(type: WorkerMessageType, payload: WorkerMessagePayload): Promise<void> {\n const data: WorkerMessageData = {source: 'loaders.gl', type, payload};\n // console.log('posting message', data);\n\n // Cast to Node compatible transfer list\n const transferList = getTransferList(payload) as TransferListItem[];\n\n const parentPort = await getParentPort();\n if (parentPort) {\n parentPort.postMessage(data, transferList);\n // console.log('posted message', data);\n } else {\n // @ts-expect-error Outside of worker scopes this call has a third parameter\n globalThis.postMessage(data, transferList);\n }\n }\n}\n\n// Filter out noise messages sent to workers\nfunction getWorkerMessageData(message: WorkerMessageEvent): WorkerMessageData | null {\n if (!message || typeof message !== 'object') {\n return null;\n }\n const messageData = 'data' in message && message.type === 'message' ? message.data : message;\n return messageData &&\n typeof messageData.source === 'string' &&\n messageData.source.startsWith('loaders.gl')\n ? messageData\n : null;\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {\n WorkerMessageType,\n WorkerMessagePayload,\n WorkerContext,\n WorkerJobContext,\n Process,\n ProcessInBatches\n} from '../../types';\nimport AsyncQueue from '../async-queue/async-queue';\nimport WorkerBody from '../worker-farm/worker-body';\n// import {validateWorkerVersion} from './validate-worker-version';\n\n/** Counter for jobs */\nlet requestId = 0;\nlet activeInputBatches: AsyncQueue<any> | null = null;\nlet activeOutputAcknowledgements: AsyncQueue<void> | null = null;\n\nexport type ProcessOnMainThread = (\n data: any,\n options?: {[key: string]: any},\n jobContext?: WorkerJobContext\n) => any;\n\n/**\n * Set up a WebWorkerGlobalScope to talk with the main thread\n */\nexport async function createWorker(\n process: Process,\n processInBatches?: ProcessInBatches\n): Promise<void> {\n if (!(await WorkerBody.inWorkerThread())) {\n return;\n }\n\n const context: WorkerContext = {\n process: processOnMainThread\n };\n\n // eslint-disable-next-line complexity\n WorkerBody.onmessage = async (type: WorkerMessageType, payload: WorkerMessagePayload) => {\n try {\n switch (type) {\n case 'preload':\n WorkerBody.postMessage('done', {});\n break;\n\n case 'process':\n if (!process) {\n throw new Error('Worker does not support atomic processing');\n }\n const result = await process(\n payload.input,\n payload.options || {},\n context,\n payload.context || {}\n );\n WorkerBody.postMessage('done', {result});\n break;\n\n case 'process-in-batches':\n if (!processInBatches) {\n throw new Error('Worker does not support batched processing');\n }\n const inputBatches = new AsyncQueue<any>();\n const outputAcknowledgements = new AsyncQueue<void>();\n activeInputBatches = inputBatches;\n activeOutputAcknowledgements = outputAcknowledgements;\n try {\n const resultIterator = processInBatches(\n createDemandDrivenIterator(inputBatches),\n payload.options || {},\n context,\n payload.context || {}\n );\n for await (const batch of resultIterator) {\n await WorkerBody.postMessage('output-batch', {result: batch});\n await outputAcknowledgements.next();\n }\n await WorkerBody.postMessage('done', {});\n } finally {\n activeInputBatches = null;\n activeOutputAcknowledgements = null;\n }\n break;\n\n case 'input-batch':\n if (!activeInputBatches) {\n throw new Error('Worker has no active batched processing session');\n }\n activeInputBatches.push(payload.input);\n break;\n\n case 'input-done':\n if (!activeInputBatches) {\n throw new Error('Worker has no active batched processing session');\n }\n activeInputBatches.close();\n break;\n\n case 'output-ack':\n if (!activeOutputAcknowledgements) {\n throw new Error('Worker has no active batched processing session');\n }\n activeOutputAcknowledgements.push(undefined);\n break;\n\n default:\n }\n } catch (error) {\n const message = error instanceof Error ? error.message : '';\n WorkerBody.postMessage('error', {error: message});\n }\n };\n}\n\n/** Requests exactly one input batch whenever the worker-side processor advances its iterator. */\nasync function* createDemandDrivenIterator(inputBatches: AsyncQueue<any>): AsyncIterable<any> {\n while (true) {\n await WorkerBody.postMessage('input-request', {});\n const nextBatch = await inputBatches.next();\n if (nextBatch.done) {\n return;\n }\n yield nextBatch.value;\n }\n}\n\nfunction processOnMainThread(arrayBuffer: ArrayBuffer, options = {}, jobContext = {}) {\n return new Promise((resolve, reject) => {\n const id = requestId++;\n\n /**\n */\n const onMessage = (type: string, payload: WorkerMessagePayload) => {\n if (payload.id !== id) {\n // not ours\n return;\n }\n\n switch (type) {\n case 'done':\n WorkerBody.removeEventListener(onMessage);\n resolve(payload.result);\n break;\n\n case 'error':\n WorkerBody.removeEventListener(onMessage);\n reject(payload.error);\n break;\n\n default:\n // ignore\n }\n };\n\n WorkerBody.addEventListener(onMessage);\n\n // Ask the main thread to decode data\n const payload = {id, input: arrayBuffer, options, context: jobContext};\n WorkerBody.postMessage('process', payload);\n });\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport {createWorker} from '../lib/worker-api/create-worker';\n\ncreateWorker(\n async data => {\n // @ts-ignore\n return data;\n },\n /** Echoes batches together with session-local state for worker protocol tests. */\n async function* processInBatches(iterator) {\n let batchIndex = 0;\n for await (const input of iterator) {\n yield {input, batchIndex};\n batchIndex++;\n }\n }\n);\n"],
|
|
5
|
-
"mappings": ";;;AAmBA,MAAqB,aAArB,MAAmC;AAAA,IACzB;AAAA,IACA;AAAA,IACA;AAAA,IAER,cAAc;AACZ,WAAK,UAAU,CAAC;AAChB,WAAK,YAAY,CAAC;AAClB,WAAK,UAAU;AAAA,IACjB;AAAA;AAAA,IAGA,CAAC,OAAO,aAAa,IAAsB;AACzC,aAAO;AAAA,IACT;AAAA;AAAA,IAGA,KAAK,OAAgB;AACnB,aAAO,KAAK,QAAQ,KAAK;AAAA,IAC3B;AAAA;AAAA;AAAA;AAAA;AAAA,IAMA,QAAQ,OAAwB;AAC9B,UAAI,KAAK,SAAS;AAChB,cAAM,IAAI,MAAM,QAAQ;AAAA,MAC1B;AAEA,UAAI,KAAK,UAAU,SAAS,GAAG;AAC7B,YAAI,KAAK,QAAQ,SAAS,GAAG;AAC3B,gBAAM,IAAI,MAAM,wBAAwB;AAAA,QAC1C;AACA,cAAM,UAAU,KAAK,UAAU,MAAM;AACrC,YAAI,iBAAiB,OAAO;AAC1B,kBAAQ,OAAO,KAAK;AAAA,QACtB,OAAO;AACL,kBAAQ,QAAQ,EAAC,MAAK,CAAC;AAAA,QACzB;AAAA,MACF,OAAO;AACL,aAAK,QAAQ,KAAK,KAAK;AAAA,MACzB;AAAA,IACF;AAAA;AAAA,IAGA,QAAc;AACZ,aAAO,KAAK,UAAU,SA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.com/rauschma/async-iter-demo/tree/master/src under MIT license\n// http://2ality.com/2016/10/asynchronous-iteration.html\n\n/**\n * Async Queue\n * - AsyncIterable: An async iterator can be\n * - Values can be pushed onto the queue\n * @example\n * const asyncQueue = new AsyncQueue();\n * setTimeout(() => asyncQueue.enqueue('tick'), 1000);\n * setTimeout(() => asyncQueue.enqueue(new Error('done')), 10000);\n * for await (const value of asyncQueue) {\n * console.log(value); // tick\n * }\n */\nexport default class AsyncQueue<T> {\n private _values: any[];\n private _settlers: any[];\n private _closed: boolean;\n\n constructor() {\n this._values = []; // enqueues > dequeues\n this._settlers = []; // dequeues > enqueues\n this._closed = false;\n }\n\n /** Return an async iterator for this queue */\n [Symbol.asyncIterator](): AsyncIterator<T> {\n return this;\n }\n\n /** Push a new value - the async iterator will yield a promise resolved to this value */\n push(value: T): void {\n return this.enqueue(value);\n }\n\n /**\n * Push a new value - the async iterator will yield a promise resolved to this value\n * Add an error - the async iterator will yield a promise rejected with this value\n */\n enqueue(value: T | Error): void {\n if (this._closed) {\n throw new Error('Closed');\n }\n\n if (this._settlers.length > 0) {\n if (this._values.length > 0) {\n throw new Error('Illegal internal state');\n }\n const settler = this._settlers.shift();\n if (value instanceof Error) {\n settler.reject(value);\n } else {\n settler.resolve({value});\n }\n } else {\n this._values.push(value);\n }\n }\n\n /** Indicate that we not waiting for more values - The async iterator will be done */\n close(): void {\n while (this._settlers.length > 0) {\n const settler = this._settlers.shift();\n settler.resolve({done: true});\n }\n this._closed = true;\n }\n\n // ITERATOR IMPLEMENTATION\n\n /** @returns a Promise for an IteratorResult */\n next(): Promise<IteratorResult<T, any>> {\n // If values in queue, yield the first value\n if (this._values.length > 0) {\n const value = this._values.shift();\n if (value instanceof Error) {\n return Promise.reject(value);\n }\n return Promise.resolve({done: false, value});\n }\n\n // If queue is closed, the iterator is done\n if (this._closed) {\n if (this._settlers.length > 0) {\n throw new Error('Illegal internal state');\n }\n return Promise.resolve({done: true, value: undefined});\n }\n\n // Yield a promise that waits for new values to be enqueued\n return new Promise((resolve, reject) => {\n this._settlers.push({resolve, reject});\n });\n }\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\n// NOTE - there is a copy of this function is both in core and loader-utils\n// core does not need all the utils in loader-utils, just this one.\n\n/**\n * Returns an array of Transferrable objects that can be used with postMessage\n * https://developer.mozilla.org/en-US/docs/Web/API/Worker/postMessage\n * @param object data to be sent via postMessage\n * @param recursive - not for application use\n * @param transfers - not for application use\n * @returns a transfer list that can be passed to postMessage\n */\nexport function getTransferList(\n object: any,\n recursive: boolean = true,\n transfers?: Set<any>\n): Transferable[] {\n // Make sure that items in the transfer list is unique\n const transfersSet = transfers || new Set();\n\n if (!object) {\n // ignore\n } else if (isTransferable(object)) {\n transfersSet.add(object);\n } else if (isTransferable(object.buffer)) {\n // Typed array\n transfersSet.add(object.buffer);\n } else if (ArrayBuffer.isView(object)) {\n // object is a TypeArray viewing into a SharedArrayBuffer (not transferable)\n // Do not iterate through the content in this case\n } else if (recursive && typeof object === 'object') {\n for (const key in object) {\n // Avoid perf hit - only go one level deep\n getTransferList(object[key], recursive, transfersSet);\n }\n }\n\n // If transfers is defined, is internal recursive call\n // Otherwise it's called by the user\n return transfers === undefined ? Array.from(transfersSet) : [];\n}\n\n// https://developer.mozilla.org/en-US/docs/Web/API/Transferable\nfunction isTransferable(object: unknown) {\n if (!object) {\n return false;\n }\n if (object instanceof ArrayBuffer) {\n return true;\n }\n if (typeof MessagePort !== 'undefined' && object instanceof MessagePort) {\n return true;\n }\n if (typeof ImageBitmap !== 'undefined' && object instanceof ImageBitmap) {\n return true;\n }\n // @ts-ignore\n if (typeof OffscreenCanvas !== 'undefined' && object instanceof OffscreenCanvas) {\n return true;\n }\n return false;\n}\n\n/**\n * Recursively drop non serializable values like functions and regexps.\n * @param object\n */\nexport function getTransferListForWriter(object: object | null): object {\n if (object === null) {\n return {};\n }\n const clone = Object.assign({}, object);\n\n Object.keys(clone).forEach(key => {\n // Typed Arrays and Arrays are passed with no change\n if (\n typeof object[key] === 'object' &&\n !ArrayBuffer.isView(object[key]) &&\n !(object[key] instanceof Array)\n ) {\n clone[key] = getTransferListForWriter(object[key]);\n } else if (typeof clone[key] === 'function' || clone[key] instanceof RegExp) {\n clone[key] = {};\n } else {\n clone[key] = object[key];\n }\n });\n\n return clone;\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\n/** Browser polyfill for Node.js built-in `worker_threads` module.\n * These fills are non-functional, and just intended to ensure that\n * `import 'worker_threads` doesn't break browser builds.\n * The replacement is done in package.json browser field\n */\nexport class NodeWorker {\n /** Restores the native worker constructor when this browser shim is embedded in a Node bundle. */\n constructor(...arguments_: unknown[]) {\n const runtimeProcess = (\n globalThis as {\n process?: {\n getBuiltinModule?: (specifier: string) => {\n Worker?: new (...workerArguments: unknown[]) => NodeWorker;\n };\n };\n }\n ).process;\n const WorkerConstructor = runtimeProcess?.getBuiltinModule?.('node:worker_threads').Worker;\n if (WorkerConstructor) {\n return new WorkerConstructor(...arguments_);\n }\n }\n\n /** No-op browser fallback matching the native Worker API. */\n terminate() {}\n}\n\nexport type {NodeWorker as NodeWorkerType};\n\nexport const parentPort = null;\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {WorkerMessageData, WorkerMessageType, WorkerMessagePayload} from '../../types';\nimport {getTransferList} from '../worker-utils/get-transfer-list';\n// import type {TransferListItem} from '../node/worker_threads';\nimport {parentPort} from '../node/worker_threads';\n\ntype TransferListItem = any;\ntype WorkerMessageEvent = MessageEvent<WorkerMessageData> | WorkerMessageData;\ntype WorkerMessageListener = (type: WorkerMessageType, payload: WorkerMessagePayload) => any;\n\n/** Vile hack to defeat over-zealous bundlers from stripping out the require */\nasync function getParentPort() {\n // const isNode = globalThis.process;\n // let parentPort;\n // try {\n // // biome-ignore format: preserve intentional fixture layout\n // eval('globalThis.parentPort = require(\\'worker_threads\\').parentPort'); // eslint-disable-line no-eval\n // parentPort = globalThis.parentPort;\n // } catch {\n // try {\n // // biome-ignore format: preserve intentional fixture layout\n // eval('globalThis.workerThreadsPromise = import(\\'worker_threads\\')'); // eslint-disable-line no-eval\n // const workerThreads = await globalThis.workerThreadsPromise;\n // parentPort = workerThreads.parentPort;\n // } catch (error) {\n // console.error((error as Error).message); // eslint-disable-line no-console\n // }\n // }\n return parentPort;\n}\n\nconst onMessageWrapperMap = new Map<WorkerMessageListener, (message: WorkerMessageEvent) => void>();\n\n/**\n * Type safe wrapper for worker code\n */\nexport default class WorkerBody {\n /** Check that we are actually in a worker thread */\n static async inWorkerThread(): Promise<boolean> {\n return typeof self !== 'undefined' || Boolean(await getParentPort());\n }\n\n /*\n * (type: WorkerMessageType, payload: WorkerMessagePayload) => any\n */\n static set onmessage(onMessage: (type: WorkerMessageType, payload: WorkerMessagePayload) => any) {\n async function handleMessage(message) {\n const parentPort = await getParentPort();\n // Confusingly the message itself also has a 'type' field which is always set to 'message'\n const {type, payload} = parentPort ? message : message.data;\n // if (!isKnownMessage(message)) {\n // return;\n // }\n onMessage(type, payload);\n }\n\n getParentPort().then(parentPort => {\n if (parentPort) {\n parentPort.on('message', message => {\n handleMessage(message);\n });\n // if (message == 'exit') { parentPort.unref(); }\n // eslint-disable-next-line\n parentPort.on('exit', () => console.debug('Node worker closing'));\n } else {\n // eslint-disable-next-line no-restricted-globals\n globalThis.onmessage = handleMessage;\n }\n });\n }\n\n static async addEventListener(onMessage: WorkerMessageListener) {\n let onMessageWrapper = onMessageWrapperMap.get(onMessage);\n\n if (!onMessageWrapper) {\n onMessageWrapper = (message: WorkerMessageEvent) => {\n const messageData = getWorkerMessageData(message);\n if (!messageData) {\n return;\n }\n onMessage(messageData.type, messageData.payload);\n };\n onMessageWrapperMap.set(onMessage, onMessageWrapper);\n }\n\n const parentPort = await getParentPort();\n if (parentPort) {\n parentPort.on('message', onMessageWrapper);\n } else {\n globalThis.addEventListener('message', onMessageWrapper);\n }\n }\n\n static async removeEventListener(onMessage: WorkerMessageListener) {\n const onMessageWrapper = onMessageWrapperMap.get(onMessage);\n onMessageWrapperMap.delete(onMessage);\n if (!onMessageWrapper) {\n return;\n }\n const parentPort = await getParentPort();\n if (parentPort) {\n parentPort.off('message', onMessageWrapper);\n } else {\n globalThis.removeEventListener('message', onMessageWrapper);\n }\n }\n\n /**\n * Send a message from a worker to creating thread (main thread)\n * @param type\n * @param payload\n */\n static async postMessage(type: WorkerMessageType, payload: WorkerMessagePayload): Promise<void> {\n const data: WorkerMessageData = {source: 'loaders.gl', type, payload};\n // console.log('posting message', data);\n\n // Cast to Node compatible transfer list\n const transferList = getTransferList(payload) as TransferListItem[];\n\n const parentPort = await getParentPort();\n if (parentPort) {\n parentPort.postMessage(data, transferList);\n // console.log('posted message', data);\n } else {\n // @ts-expect-error Outside of worker scopes this call has a third parameter\n globalThis.postMessage(data, transferList);\n }\n }\n}\n\n// Filter out noise messages sent to workers\nfunction getWorkerMessageData(message: WorkerMessageEvent): WorkerMessageData | null {\n if (!message || typeof message !== 'object') {\n return null;\n }\n const messageData = 'data' in message && message.type === 'message' ? message.data : message;\n return messageData &&\n typeof messageData.source === 'string' &&\n messageData.source.startsWith('loaders.gl')\n ? messageData\n : null;\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {\n WorkerProgress,\n WorkerMessageType,\n WorkerMessagePayload,\n WorkerContext,\n WorkerJobContext,\n Process,\n ProcessInBatches\n} from '../../types';\nimport AsyncQueue from '../async-queue/async-queue';\nimport WorkerBody from '../worker-farm/worker-body';\n// import {validateWorkerVersion} from './validate-worker-version';\n\n/** Counter for jobs */\nlet requestId = 0;\nlet activeInputBatches: AsyncQueue<any> | null = null;\nlet activeOutputAcknowledgements: AsyncQueue<void> | null = null;\n\nexport type ProcessOnMainThread = (\n data: any,\n options?: {[key: string]: any},\n jobContext?: WorkerJobContext\n) => any;\n\n/**\n * Set up a WebWorkerGlobalScope to talk with the main thread\n */\nexport async function createWorker(\n process: Process,\n processInBatches?: ProcessInBatches\n): Promise<void> {\n if (!(await WorkerBody.inWorkerThread())) {\n return;\n }\n\n const context: WorkerContext = {\n process: processOnMainThread\n };\n\n // eslint-disable-next-line complexity\n WorkerBody.onmessage = async (type: WorkerMessageType, payload: WorkerMessagePayload) => {\n const reporter =\n type === 'process' || type === 'process-in-batches' ? createProgressReporter() : undefined;\n const jobContext = {...context, reportProgress: reporter?.report};\n try {\n switch (type) {\n case 'preload':\n WorkerBody.postMessage('done', {});\n break;\n\n case 'process':\n if (!process) {\n throw new Error('Worker does not support atomic processing');\n }\n const result = await process(\n payload.input,\n payload.options || {},\n jobContext,\n payload.context || {}\n );\n reporter?.finish();\n WorkerBody.postMessage('done', {result});\n break;\n\n case 'process-in-batches':\n if (!processInBatches) {\n throw new Error('Worker does not support batched processing');\n }\n const inputBatches = new AsyncQueue<any>();\n const outputAcknowledgements = new AsyncQueue<void>();\n activeInputBatches = inputBatches;\n activeOutputAcknowledgements = outputAcknowledgements;\n try {\n const resultIterator = processInBatches(\n createDemandDrivenIterator(inputBatches),\n payload.options || {},\n jobContext,\n payload.context || {}\n );\n for await (const batch of resultIterator) {\n await WorkerBody.postMessage('output-batch', {result: batch});\n await outputAcknowledgements.next();\n }\n reporter?.finish();\n await WorkerBody.postMessage('done', {});\n } finally {\n activeInputBatches = null;\n activeOutputAcknowledgements = null;\n }\n break;\n\n case 'input-batch':\n if (!activeInputBatches) {\n throw new Error('Worker has no active batched processing session');\n }\n activeInputBatches.push(payload.input);\n break;\n\n case 'input-done':\n if (!activeInputBatches) {\n throw new Error('Worker has no active batched processing session');\n }\n activeInputBatches.close();\n break;\n\n case 'output-ack':\n if (!activeOutputAcknowledgements) {\n throw new Error('Worker has no active batched processing session');\n }\n activeOutputAcknowledgements.push(undefined);\n break;\n\n default:\n }\n } catch (error) {\n reporter?.finish();\n const message = error instanceof Error ? error.message : '';\n WorkerBody.postMessage('error', {error: message});\n }\n };\n}\n\n/** Requests exactly one input batch whenever the worker-side processor advances its iterator. */\nasync function* createDemandDrivenIterator(inputBatches: AsyncQueue<any>): AsyncIterable<any> {\n while (true) {\n await WorkerBody.postMessage('input-request', {});\n const nextBatch = await inputBatches.next();\n if (nextBatch.done) {\n return;\n }\n yield nextBatch.value;\n }\n}\n\nfunction processOnMainThread(arrayBuffer: ArrayBuffer, options = {}, jobContext = {}) {\n return new Promise((resolve, reject) => {\n const id = requestId++;\n\n /**\n */\n const onMessage = (type: string, payload: WorkerMessagePayload) => {\n if (payload.id !== id) {\n // not ours\n return;\n }\n\n switch (type) {\n case 'done':\n WorkerBody.removeEventListener(onMessage);\n resolve(payload.result);\n break;\n\n case 'error':\n WorkerBody.removeEventListener(onMessage);\n reject(payload.error);\n break;\n\n default:\n // ignore\n }\n };\n\n WorkerBody.addEventListener(onMessage);\n\n // Ask the main thread to decode data\n const payload = {id, input: arrayBuffer, options, context: jobContext};\n WorkerBody.postMessage('process', payload);\n });\n}\n\n/** Coalesces same-phase reports per event-loop turn and flushes before settlement. */\nfunction createProgressReporter() {\n let pending: WorkerProgress | undefined;\n let finished = false;\n let scheduled = false;\n /** Posts the latest pending measurement. */\n const flush = (): void => {\n scheduled = false;\n if (pending) {\n WorkerBody.postMessage('progress', {progress: pending});\n pending = undefined;\n }\n };\n return {\n /** Records progress while retaining phase transitions. */\n report(progress: WorkerProgress): void {\n if (finished) return;\n if (pending && pending.phase !== progress.phase) flush();\n pending = {...progress};\n if (!scheduled) {\n scheduled = true;\n setTimeout(flush, 0);\n }\n },\n /** Flushes final progress and suppresses reports from stale callbacks. */\n finish(): void {\n flush();\n finished = true;\n }\n };\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport {createWorker} from '../lib/worker-api/create-worker';\n\ncreateWorker(\n async data => {\n // @ts-ignore\n return data;\n },\n /** Echoes batches together with session-local state for worker protocol tests. */\n async function* processInBatches(iterator) {\n let batchIndex = 0;\n for await (const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AAAA;AAAA,MAEL,OAAO,UAAgC;AACrC,YAAI,SAAU;AACd,YAAI,WAAW,QAAQ,UAAU,SAAS,MAAO,OAAM;AACvD,kBAAU,EAAC,GAAG,SAAQ;AACtB,YAAI,CAAC,WAAW;AACd,sBAAY;AACZ,qBAAW,OAAO,CAAC;AAAA,QACrB;AAAA,MACF;AAAA;AAAA,MAEA,SAAe;AACb,cAAM;AACN,mBAAW;AAAA,MACb;AAAA,IACF;AAAA,EACF;;;ACtMA;AAAA,IACE,OAAM,SAAQ;AAEZ,aAAO;AAAA,IACT;AAAA;AAAA,IAEA,gBAAgB,iBAAiB,UAAU;AACzC,UAAI,aAAa;AACjB,uBAAiB,SAAS,UAAU;AAClC,cAAM,EAAC,OAAO,WAAU;AACxB;AAAA,MACF;AAAA,IACF;AAAA,EACF;",
|
|
6
6
|
"names": ["parentPort", "processInBatches", "payload"]
|
|
7
7
|
}
|
|
@@ -1,9 +1,24 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
*/
|
|
1
|
+
/** Progress measured independently within a named phase. */
|
|
2
|
+
export type WorkerProgress = {
|
|
3
|
+
/** Operation being measured. */
|
|
4
|
+
phase: string;
|
|
5
|
+
/** Work completed in this phase. */
|
|
6
|
+
completed: number;
|
|
7
|
+
/** Expected work, when known. */
|
|
8
|
+
total?: number;
|
|
9
|
+
/** Measurement unit, such as bytes, rows, or tasks. */
|
|
10
|
+
unit: string;
|
|
11
|
+
};
|
|
12
|
+
/** Shared worker execution options. */
|
|
4
13
|
export type WorkerOptions = {
|
|
14
|
+
/** Cancels queued or running work. */
|
|
15
|
+
signal?: AbortSignal;
|
|
16
|
+
/** Receives phase progress. Throwing aborts the job with that error. */
|
|
17
|
+
onProgress?: (progress: WorkerProgress) => void;
|
|
5
18
|
CDN?: string | null;
|
|
6
19
|
worker?: boolean;
|
|
20
|
+
/** Declares batch-protocol support for a custom worker, or disables batch offloading. */
|
|
21
|
+
workerInBatches?: boolean;
|
|
7
22
|
maxConcurrency?: number;
|
|
8
23
|
maxMobileConcurrency?: number;
|
|
9
24
|
reuseWorkers?: boolean;
|
|
@@ -19,6 +34,8 @@ export type WorkerOptions = {
|
|
|
19
34
|
*/
|
|
20
35
|
export type LoadWorker = () => Worker | null;
|
|
21
36
|
export type WorkerContext = {
|
|
37
|
+
/** Reports progress from the active worker job. */
|
|
38
|
+
reportProgress?: (progress: WorkerProgress) => void;
|
|
22
39
|
process?: Process;
|
|
23
40
|
processInBatches?: ProcessInBatches;
|
|
24
41
|
};
|
|
@@ -41,6 +58,8 @@ export type WorkerObject = {
|
|
|
41
58
|
module: string;
|
|
42
59
|
version: string;
|
|
43
60
|
worker?: string | boolean;
|
|
61
|
+
/** Whether the built-in worker accepts stateful batch requests. */
|
|
62
|
+
workerInBatches?: boolean;
|
|
44
63
|
/** Browser worker filename when it differs from the worker id. */
|
|
45
64
|
workerFile?: string;
|
|
46
65
|
/** Creates a built-in browser worker, typically using `type: 'module'`. */
|
|
@@ -56,8 +75,10 @@ export type WorkerObject = {
|
|
|
56
75
|
process?: Process;
|
|
57
76
|
processInBatches?: ProcessInBatches;
|
|
58
77
|
};
|
|
59
|
-
export type WorkerMessageType = 'preload' | 'process' | 'done' | 'error' | 'process-in-batches' | 'input-request' | 'input-batch' | 'input-done' | 'output-batch' | 'output-ack';
|
|
78
|
+
export type WorkerMessageType = 'progress' | 'preload' | 'process' | 'done' | 'error' | 'process-in-batches' | 'input-request' | 'input-batch' | 'input-done' | 'output-batch' | 'output-ack';
|
|
60
79
|
export type WorkerMessagePayload = {
|
|
80
|
+
/** Phase progress from the worker. */
|
|
81
|
+
progress?: WorkerProgress;
|
|
61
82
|
id?: number;
|
|
62
83
|
options?: {
|
|
63
84
|
[key: string]: any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/worker-utils/types.ts"],"names":[],"mappings":"AAIA
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":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,MAAM,GACN,OAAO,GACP,oBAAoB,GACpB,eAAe,GACf,aAAa,GACb,YAAY,GACZ,cAAc,GACd,YAAY,CAAC;AAEjB,MAAM,MAAM,oBAAoB,GAAG;IACjC,sCAAsC;IACtC,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC,CAAC;IAC/B,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAC3B,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,EAAE,YAAY,CAAC;IACrB,IAAI,EAAE,iBAAiB,CAAC;IACxB,OAAO,EAAE,oBAAoB,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,iBAAiB,CAAC;CACzB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/core",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.14",
|
|
4
4
|
"description": "The core API for working with loaders.gl loaders and writers",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -131,14 +131,14 @@
|
|
|
131
131
|
"generate-json-schema": "node ../../scripts/generate-json-schema.mjs --schema ./dist/schema/geospatial-metadata-zod-schema.js --export GeoParquetMetadataSchema --output ./dist/schema/geoparquet.schema.json --id https://unpkg.com/@loaders.gl/core/schema/geoparquet.schema.json --title 'loaders.gl GeoParquet metadata' && node ../../scripts/generate-json-schema.mjs --schema ./dist/schema/geospatial-metadata-zod-schema.js --export GeoArrowMetadataSchema --output ./dist/schema/geoarrow-metadata.schema.json --id https://unpkg.com/@loaders.gl/core/schema/geoarrow-metadata.schema.json --title 'loaders.gl GeoArrow field metadata'"
|
|
132
132
|
},
|
|
133
133
|
"dependencies": {
|
|
134
|
-
"@math.gl/core": "5.0.0-alpha.
|
|
135
|
-
"@math.gl/geospatial": "5.0.0-alpha.
|
|
134
|
+
"@math.gl/core": "5.0.0-alpha.20",
|
|
135
|
+
"@math.gl/geospatial": "5.0.0-alpha.20",
|
|
136
136
|
"@types/geojson": "^7946.0.7",
|
|
137
137
|
"apache-arrow": ">= 17.0.0",
|
|
138
138
|
"probe.gl": "^5.0.0",
|
|
139
139
|
"zod": "^4.1.12"
|
|
140
140
|
},
|
|
141
|
-
"gitHead": "
|
|
141
|
+
"gitHead": "226b7bca7ecb3684b7386487ee76565ca240d7d9",
|
|
142
142
|
"peerDependencies": {
|
|
143
143
|
"get-pixels": "^3.3.3",
|
|
144
144
|
"ndarray": "^1.0.19",
|
|
@@ -85,6 +85,7 @@ export async function parseFile(
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
options = options || {};
|
|
88
|
+
(options.signal || context?.signal)?.throwIfAborted();
|
|
88
89
|
const url = file.url || '';
|
|
89
90
|
const typedLoaders = loaders as Loader | Loader[] | undefined;
|
|
90
91
|
const candidateLoaders = getLoadersFromContext(typedLoaders, context);
|
|
@@ -134,6 +135,7 @@ async function parseFileWithLoader(
|
|
|
134
135
|
options: StrictLoaderOptions,
|
|
135
136
|
context: LoaderContext
|
|
136
137
|
): Promise<unknown> {
|
|
138
|
+
(options.signal || context.signal)?.throwIfAborted();
|
|
137
139
|
validateWorkerVersion(loader);
|
|
138
140
|
options = mergeOptions(loader.options, options);
|
|
139
141
|
|
|
@@ -20,9 +20,8 @@ import type {
|
|
|
20
20
|
TransformBatches
|
|
21
21
|
} from '@loaders.gl/core/loader-utils';
|
|
22
22
|
import {
|
|
23
|
-
|
|
23
|
+
canParseWithWorkerInBatches,
|
|
24
24
|
concatenateArrayBuffersAsync,
|
|
25
|
-
isBrowser,
|
|
26
25
|
parseWithWorkerInBatches
|
|
27
26
|
} from '@loaders.gl/core/loader-utils';
|
|
28
27
|
import {isLoaderObject} from '../loader-utils/normalize-loader';
|
|
@@ -97,8 +96,10 @@ export async function parseInBatches(
|
|
|
97
96
|
loaders = undefined;
|
|
98
97
|
}
|
|
99
98
|
|
|
99
|
+
(options?.signal || context?.signal)?.throwIfAborted();
|
|
100
100
|
data = await data; // Resolve any promise
|
|
101
101
|
options = options || {};
|
|
102
|
+
(options.signal || context?.signal)?.throwIfAborted();
|
|
102
103
|
|
|
103
104
|
// Extract a url for auto detection
|
|
104
105
|
const url = getResourceUrl(data);
|
|
@@ -191,10 +192,9 @@ async function parseToOutputIterator(
|
|
|
191
192
|
options?.core?.transforms || []
|
|
192
193
|
);
|
|
193
194
|
|
|
194
|
-
//
|
|
195
|
+
// Lease one worker for the complete iterator when the loader advertises batch support.
|
|
195
196
|
if (loader.parseInBatches) {
|
|
196
|
-
|
|
197
|
-
if (loader.id === 'csv' && isBrowser && canParseWithWorker(loader, options)) {
|
|
197
|
+
if (canParseWithWorkerInBatches(loader, options)) {
|
|
198
198
|
return parseWithWorkerInBatches(loader, transformedIterator, options, context, parse);
|
|
199
199
|
}
|
|
200
200
|
return loader.parseInBatches(transformedIterator, options, context);
|