@loaders.gl/core 5.0.0-beta.4 → 5.0.0-beta.5
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/GEOARROW-README.md +1 -1
- package/README.md +1 -1
- package/SCAN-README.md +1 -1
- package/SCHEMA-UTILS-README.md +1 -1
- package/dist/arrow-geometry/binary-geometry-to-wkb.cjs +2 -2
- package/dist/arrow-geometry/binary-geometry-to-wkb.cjs.map +2 -2
- package/dist/arrow-geometry/binary-geometry-to-wkb.js +1 -1
- package/dist/arrow-geometry/binary-geometry-to-wkb.js.map +1 -1
- package/dist/arrow-geometry/geojson-table.cjs +3 -3
- package/dist/arrow-geometry/geojson-table.cjs.map +2 -2
- package/dist/arrow-geometry/geojson-table.js +2 -2
- package/dist/arrow-geometry/geojson-table.js.map +1 -1
- package/dist/arrow-geometry/geometry-codecs.cjs +6 -6
- package/dist/arrow-geometry/geometry-codecs.cjs.map +2 -2
- package/dist/arrow-geometry/geometry-codecs.js +1 -1
- package/dist/arrow-geometry/geometry-codecs.js.map +1 -1
- package/dist/arrow-geometry/geometry-to-wkt.cjs +2 -2
- package/dist/arrow-geometry/geometry-to-wkt.cjs.map +2 -2
- package/dist/arrow-geometry/geometry-to-wkt.js +1 -1
- package/dist/arrow-geometry/geometry-to-wkt.js.map +1 -1
- package/dist/arrow-geometry/index.cjs +0 -11
- package/dist/arrow-geometry/index.cjs.map +2 -2
- package/dist/arrow-geometry/index.d.ts +0 -1
- package/dist/arrow-geometry/index.d.ts.map +1 -1
- package/dist/arrow-geometry/index.js +0 -1
- package/dist/arrow-geometry/index.js.map +1 -1
- package/dist/arrow-geometry/wkb-builder.cjs +3 -3
- package/dist/arrow-geometry/wkb-builder.cjs.map +2 -2
- package/dist/arrow-geometry/wkb-builder.d.ts +1 -1
- package/dist/arrow-geometry/wkb-builder.d.ts.map +1 -1
- package/dist/arrow-geometry/wkb-builder.js +1 -1
- package/dist/arrow-geometry/wkb-builder.js.map +1 -1
- package/dist/arrow-geometry/wkb-statistics.cjs +2 -2
- package/dist/arrow-geometry/wkb-statistics.cjs.map +2 -2
- package/dist/arrow-geometry/wkb-statistics.js +1 -1
- package/dist/arrow-geometry/wkb-statistics.js.map +1 -1
- package/dist/arrow-worker-transport.cjs +81 -0
- package/dist/arrow-worker-transport.cjs.map +6 -0
- package/dist/arrow-worker-transport.d.ts +9 -0
- package/dist/arrow-worker-transport.d.ts.map +1 -0
- package/dist/arrow-worker-transport.js +60 -0
- package/dist/arrow-worker-transport.js.map +1 -0
- package/dist/cluster-source.cjs +153 -584
- package/dist/cluster-source.cjs.map +3 -3
- package/dist/dist.dev.js +546 -54
- package/dist/dist.min.js +3 -3
- package/dist/geoarrow/binary-polygon-to-geoarrow.cjs +2 -2
- package/dist/geoarrow/binary-polygon-to-geoarrow.cjs.map +2 -2
- package/dist/geoarrow/binary-polygon-to-geoarrow.d.ts +1 -1
- package/dist/geoarrow/binary-polygon-to-geoarrow.d.ts.map +1 -1
- package/dist/geoarrow/binary-polygon-to-geoarrow.js +1 -1
- package/dist/geoarrow/binary-polygon-to-geoarrow.js.map +1 -1
- package/dist/geoarrow/geoarrow-bounds.cjs +7 -7
- package/dist/geoarrow/geoarrow-bounds.cjs.map +2 -2
- package/dist/geoarrow/geoarrow-bounds.js +3 -3
- package/dist/geoarrow/geoarrow-bounds.js.map +1 -1
- package/dist/geoarrow/geoarrow-capabilities.cjs +2 -2
- package/dist/geoarrow/geoarrow-capabilities.cjs.map +2 -2
- package/dist/geoarrow/geoarrow-capabilities.js +1 -1
- package/dist/geoarrow/geoarrow-capabilities.js.map +1 -1
- package/dist/geoarrow/geoarrow-converter/convert-geoarrow-geometry.cjs +8 -8
- package/dist/geoarrow/geoarrow-converter/convert-geoarrow-geometry.cjs.map +2 -2
- package/dist/geoarrow/geoarrow-converter/convert-geoarrow-geometry.js +2 -2
- package/dist/geoarrow/geoarrow-converter/convert-geoarrow-geometry.js.map +1 -1
- package/dist/geoarrow/geoarrow-converter/geoarrow-converter.d.ts +2 -2
- package/dist/geoarrow/geoarrow-inspection.cjs +2 -2
- package/dist/geoarrow/geoarrow-inspection.cjs.map +2 -2
- package/dist/geoarrow/geoarrow-inspection.js +1 -1
- package/dist/geoarrow/geoarrow-inspection.js.map +1 -1
- package/dist/geoarrow/geoarrow-stream.cjs +1 -1
- package/dist/geoarrow/geoarrow-stream.cjs.map +2 -2
- package/dist/geoarrow/geoarrow-stream.js +1 -1
- package/dist/geoarrow/geoarrow-stream.js.map +1 -1
- package/dist/geoarrow/get-geoarrow-vertex-count.cjs +2 -2
- package/dist/geoarrow/get-geoarrow-vertex-count.cjs.map +2 -2
- package/dist/geoarrow/get-geoarrow-vertex-count.js +1 -1
- package/dist/geoarrow/get-geoarrow-vertex-count.js.map +1 -1
- package/dist/geoarrow/lib/geometry-converters/wkb/convert-wkb-to-binary-geometry.cjs +4 -4
- package/dist/geoarrow/lib/geometry-converters/wkb/convert-wkb-to-binary-geometry.cjs.map +2 -2
- package/dist/geoarrow/lib/geometry-converters/wkb/convert-wkb-to-binary-geometry.js +1 -1
- package/dist/geoarrow/lib/geometry-converters/wkb/convert-wkb-to-binary-geometry.js.map +1 -1
- package/dist/geoarrow/lib/geometry-converters/wkb/helpers/parse-wkb-header.cjs +3 -3
- package/dist/geoarrow/lib/geometry-converters/wkb/helpers/parse-wkb-header.cjs.map +2 -2
- package/dist/geoarrow/lib/geometry-converters/wkb/helpers/parse-wkb-header.js +1 -1
- package/dist/geoarrow/lib/geometry-converters/wkb/helpers/parse-wkb-header.js.map +1 -1
- package/dist/geoarrow/lib/kernels/encode-geoarrow-box.cjs +3 -3
- package/dist/geoarrow/lib/kernels/encode-geoarrow-box.cjs.map +2 -2
- package/dist/geoarrow/lib/kernels/encode-geoarrow-box.js +1 -1
- package/dist/geoarrow/lib/kernels/encode-geoarrow-box.js.map +1 -1
- package/dist/index.cjs +8 -11
- package/dist/index.cjs.map +3 -3
- package/dist/lib/init.js +1 -1
- package/dist/loader-utils/index.cjs +20 -23
- package/dist/loader-utils/index.cjs.map +3 -3
- package/dist/loader-utils/index.js +1 -1
- package/dist/loader-utils/json-loader.js +1 -1
- package/dist/loader-utils/lib/log-utils/log.js +1 -1
- package/dist/null-loader.js +1 -1
- package/dist/null-worker-node.js +244 -11
- package/dist/null-worker.js +239 -11
- package/dist/schema/geometry/geoarrow.d.ts +3 -6
- package/dist/schema/geometry/geoarrow.d.ts.map +1 -1
- package/dist/worker-utils/index.cjs +19 -26
- package/dist/worker-utils/index.cjs.map +3 -3
- package/dist/worker-utils/index.d.ts +0 -3
- package/dist/worker-utils/index.d.ts.map +1 -1
- package/dist/worker-utils/index.js +0 -3
- package/dist/worker-utils/index.js.map +1 -1
- package/dist/worker-utils/lib/env-utils/version.js +1 -1
- package/dist/worker-utils/lib/worker-api/process-on-worker.d.ts +1 -1
- 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 +1 -1
- package/dist/worker-utils/lib/worker-api/process-on-worker.js.map +1 -1
- package/dist/worker-utils/lib/worker-api/task-runtime.d.ts +1 -1
- package/dist/worker-utils/lib/worker-api/task-runtime.d.ts.map +1 -1
- package/dist/worker-utils/lib/worker-api/task-runtime.js +1 -1
- package/dist/worker-utils/lib/worker-api/task-runtime.js.map +1 -1
- package/dist/worker-utils/null-worker-node.js +243 -10
- package/dist/worker-utils/null-worker-node.js.map +4 -4
- package/dist/worker-utils/null-worker.js +238 -10
- package/dist/worker-utils/null-worker.js.map +4 -4
- package/dist/worker-utils/types.d.ts +1 -1
- package/dist/worker-utils/types.d.ts.map +1 -1
- package/package.json +13 -11
- package/src/arrow-geometry/binary-geometry-to-wkb.ts +1 -1
- package/src/arrow-geometry/geojson-table.ts +2 -2
- package/src/arrow-geometry/geometry-codecs.ts +2 -2
- package/src/arrow-geometry/geometry-to-wkt.ts +2 -2
- package/src/arrow-geometry/index.ts +0 -9
- package/src/arrow-geometry/wkb-builder.ts +2 -2
- package/src/arrow-geometry/wkb-statistics.ts +2 -2
- package/src/arrow-worker-transport.ts +87 -0
- package/src/geoarrow/binary-polygon-to-geoarrow.ts +2 -2
- package/src/geoarrow/geoarrow-bounds.ts +3 -3
- package/src/geoarrow/geoarrow-capabilities.ts +1 -1
- package/src/geoarrow/geoarrow-converter/convert-geoarrow-geometry.ts +3 -3
- package/src/geoarrow/geoarrow-inspection.ts +2 -2
- package/src/geoarrow/geoarrow-stream.ts +1 -1
- package/src/geoarrow/get-geoarrow-vertex-count.ts +1 -1
- package/src/geoarrow/lib/geometry-converters/wkb/convert-wkb-to-binary-geometry.ts +1 -1
- package/src/geoarrow/lib/geometry-converters/wkb/helpers/parse-wkb-header.ts +2 -2
- package/src/geoarrow/lib/kernels/encode-geoarrow-box.ts +1 -1
- package/src/loader-utils/index.ts +1 -1
- package/src/schema/geometry/geoarrow.ts +8 -19
- package/src/worker-utils/index.ts +0 -16
- package/src/worker-utils/lib/worker-api/create-worker.ts +1 -1
- package/src/worker-utils/lib/worker-api/process-on-worker.ts +1 -6
- package/src/worker-utils/lib/worker-api/task-runtime.ts +1 -1
- package/src/worker-utils/types.ts +1 -1
- package/dist/arrow-geometry/arrow-geoarrow-adapter.cjs +0 -477
- package/dist/arrow-geometry/arrow-geoarrow-adapter.cjs.map +0 -7
- package/dist/arrow-geometry/arrow-geoarrow-adapter.d.ts +0 -29
- package/dist/arrow-geometry/arrow-geoarrow-adapter.d.ts.map +0 -1
- package/dist/arrow-geometry/arrow-geoarrow-adapter.js +0 -434
- package/dist/arrow-geometry/arrow-geoarrow-adapter.js.map +0 -1
- package/dist/geoarrow/lib/arrow-geoarrow-adapter.cjs +0 -39
- package/dist/geoarrow/lib/arrow-geoarrow-adapter.cjs.map +0 -7
- package/dist/geoarrow/lib/arrow-geoarrow-adapter.d.ts +0 -2
- package/dist/geoarrow/lib/arrow-geoarrow-adapter.d.ts.map +0 -1
- package/dist/geoarrow/lib/arrow-geoarrow-adapter.js +0 -5
- package/dist/geoarrow/lib/arrow-geoarrow-adapter.js.map +0 -1
- package/dist/schema-utils/arrow-transport.cjs +0 -691
- package/dist/schema-utils/arrow-transport.cjs.map +0 -6
- package/dist/schema-utils/arrow-transport.d.ts +0 -4
- package/dist/schema-utils/arrow-transport.d.ts.map +0 -1
- package/dist/schema-utils/arrow-transport.js +0 -7
- package/dist/schema-utils/arrow-transport.js.map +0 -1
- package/dist/schema-utils/lib/arrow/arrow-table-transport.d.ts +0 -76
- package/dist/schema-utils/lib/arrow/arrow-table-transport.d.ts.map +0 -1
- package/dist/schema-utils/lib/arrow/arrow-table-transport.js +0 -182
- package/dist/schema-utils/lib/arrow/arrow-table-transport.js.map +0 -1
- package/dist/schema-utils/lib/arrow/split-arrow-buffers.d.ts +0 -33
- package/dist/schema-utils/lib/arrow/split-arrow-buffers.d.ts.map +0 -1
- package/dist/schema-utils/lib/arrow/split-arrow-buffers.js +0 -134
- package/dist/schema-utils/lib/arrow/split-arrow-buffers.js.map +0 -1
- package/src/arrow-geometry/arrow-geoarrow-adapter.ts +0 -568
- package/src/geoarrow/lib/arrow-geoarrow-adapter.ts +0 -12
- package/src/schema-utils/arrow-transport.ts +0 -7
- package/src/schema-utils/lib/arrow/arrow-table-transport.ts +0 -282
- package/src/schema-utils/lib/arrow/split-arrow-buffers.ts +0 -247
|
@@ -42,10 +42,10 @@
|
|
|
42
42
|
}
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
-
// ../../node_modules/@math.gl/
|
|
45
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/node/worker_threads-browser.js
|
|
46
46
|
var parentPort = globalThis.process?.getBuiltinModule?.("node:worker_threads")?.parentPort ?? null;
|
|
47
47
|
|
|
48
|
-
// ../../node_modules/@math.gl/
|
|
48
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-utils/get-transfer-list.js
|
|
49
49
|
function getTransferList(object, recursive = true, transfers) {
|
|
50
50
|
const transfersSet = transfers || /* @__PURE__ */ new Set();
|
|
51
51
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
return false;
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
// ../../node_modules/@math.gl/
|
|
99
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-farm/worker-body.js
|
|
100
100
|
async function getParentPort() {
|
|
101
101
|
return parentPort;
|
|
102
102
|
}
|
|
@@ -183,7 +183,7 @@
|
|
|
183
183
|
return messageData && typeof messageData.source === "string" && messageData.source.startsWith("loaders.gl") ? messageData : null;
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
-
// ../../node_modules/@math.gl/
|
|
186
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/async-queue/async-queue.js
|
|
187
187
|
var AsyncQueue = class {
|
|
188
188
|
constructor() {
|
|
189
189
|
this._values = [];
|
|
@@ -250,7 +250,7 @@
|
|
|
250
250
|
}
|
|
251
251
|
};
|
|
252
252
|
|
|
253
|
-
// ../../node_modules/@math.gl/
|
|
253
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-api/shared-state.js
|
|
254
254
|
var SharedWorkerState = class {
|
|
255
255
|
constructor(buffer) {
|
|
256
256
|
if (typeof SharedArrayBuffer === "undefined" || !(buffer instanceof SharedArrayBuffer) || buffer.byteLength !== 16)
|
|
@@ -289,14 +289,14 @@
|
|
|
289
289
|
}
|
|
290
290
|
};
|
|
291
291
|
|
|
292
|
-
// ../../node_modules/@math.gl/
|
|
292
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-api/validate-output-ownership.js
|
|
293
293
|
function validateOutputOwnership(ownership) {
|
|
294
294
|
if (ownership !== void 0 && ownership !== "copy" && ownership !== "transfer") {
|
|
295
295
|
throw new Error("Invalid worker output ownership");
|
|
296
296
|
}
|
|
297
297
|
}
|
|
298
298
|
|
|
299
|
-
// ../../node_modules/@math.gl/
|
|
299
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/lib/worker-api/create-worker.js
|
|
300
300
|
var requestId = 0;
|
|
301
301
|
var activeController = null;
|
|
302
302
|
var activeInputBatches = null;
|
|
@@ -504,12 +504,12 @@
|
|
|
504
504
|
};
|
|
505
505
|
}
|
|
506
506
|
|
|
507
|
-
// ../../node_modules/@math.gl/
|
|
507
|
+
// ../../node_modules/@math.gl/tasks/dist/worker-utils/index.js
|
|
508
508
|
var import_meta = {};
|
|
509
509
|
var path = typeof __filename === "string" ? __filename.replace(/\\/g, "/") : "";
|
|
510
510
|
var moduleUrl = path ? `file://${path.startsWith("/") ? "" : "/"}${encodeURI(path).replace(/#/g, "%23").replace(/\?/g, "%3F")}` : import_meta.url;
|
|
511
511
|
|
|
512
|
-
// ../../node_modules/@math.gl/
|
|
512
|
+
// ../../node_modules/@math.gl/tasks/dist/tasks/task-preload.js
|
|
513
513
|
var pending = /* @__PURE__ */ new WeakMap();
|
|
514
514
|
var loaded = /* @__PURE__ */ new WeakSet();
|
|
515
515
|
function preloadTaskCode(task, signal) {
|
|
@@ -546,17 +546,182 @@
|
|
|
546
546
|
});
|
|
547
547
|
}
|
|
548
548
|
|
|
549
|
-
// ../../node_modules/@math.gl/
|
|
549
|
+
// ../../node_modules/@math.gl/tasks/dist/tasks/task-channel.js
|
|
550
|
+
var TaskRequestError = class extends Error {
|
|
551
|
+
};
|
|
552
|
+
var TaskChannel = class {
|
|
553
|
+
constructor(options) {
|
|
554
|
+
this.options = options;
|
|
555
|
+
this.nextId = 1;
|
|
556
|
+
this.pending = /* @__PURE__ */ new Map();
|
|
557
|
+
this.incoming = /* @__PURE__ */ new Map();
|
|
558
|
+
}
|
|
559
|
+
/** Send a request without serializing other in-flight requests. */
|
|
560
|
+
request(operation, value, signal, transfer = []) {
|
|
561
|
+
if (this.failure)
|
|
562
|
+
return Promise.reject(this.failure.reason);
|
|
563
|
+
if (signal?.aborted)
|
|
564
|
+
return Promise.reject(signal.reason);
|
|
565
|
+
const id = this.nextId++;
|
|
566
|
+
return new Promise((resolve, reject) => {
|
|
567
|
+
const abort = () => {
|
|
568
|
+
const pending2 = this.pending.get(id);
|
|
569
|
+
if (!pending2)
|
|
570
|
+
return;
|
|
571
|
+
this.pending.delete(id);
|
|
572
|
+
pending2.cleanup();
|
|
573
|
+
reject(signal?.reason);
|
|
574
|
+
this.send({ source: "math.gl/tasks", kind: "cancel", id });
|
|
575
|
+
};
|
|
576
|
+
this.pending.set(id, {
|
|
577
|
+
resolve,
|
|
578
|
+
reject,
|
|
579
|
+
cleanup: () => signal?.removeEventListener("abort", abort)
|
|
580
|
+
});
|
|
581
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
582
|
+
this.send({ source: "math.gl/tasks", kind: "request", id, operation, value }, transfer);
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
/** Send a one-way notification. */
|
|
586
|
+
emit(operation, value, transfer = []) {
|
|
587
|
+
if (this.failure)
|
|
588
|
+
throw this.failure.reason;
|
|
589
|
+
this.send({ source: "math.gl/tasks", kind: "event", id: 0, operation, value }, transfer);
|
|
590
|
+
}
|
|
591
|
+
/** Dispatch a transport message; unrelated protocols are ignored. */
|
|
592
|
+
receive(message) {
|
|
593
|
+
if (this.failure || message?.source !== "math.gl/tasks")
|
|
594
|
+
return;
|
|
595
|
+
if (message.kind === "failure") {
|
|
596
|
+
const reason = new Error(message.error?.message ?? "Task channel failed");
|
|
597
|
+
this.close(reason);
|
|
598
|
+
this.options.onFailure?.(reason);
|
|
599
|
+
} else if (message.kind === "result" || message.kind === "error") {
|
|
600
|
+
const pending2 = this.pending.get(message.id);
|
|
601
|
+
if (!pending2)
|
|
602
|
+
return;
|
|
603
|
+
this.pending.delete(message.id);
|
|
604
|
+
pending2.cleanup();
|
|
605
|
+
if (message.kind === "result")
|
|
606
|
+
pending2.resolve(message.value);
|
|
607
|
+
else {
|
|
608
|
+
const error = new TaskRequestError(message.error?.message ?? "Task request failed");
|
|
609
|
+
error.name = message.error?.name ?? "Error";
|
|
610
|
+
pending2.reject(error);
|
|
611
|
+
}
|
|
612
|
+
} else if (message.kind === "cancel") {
|
|
613
|
+
this.incoming.get(message.id)?.abort(new DOMException("Task request cancelled", "AbortError"));
|
|
614
|
+
} else if (message.kind === "event") {
|
|
615
|
+
try {
|
|
616
|
+
this.options.handleEvent?.(message.operation, message.value);
|
|
617
|
+
} catch (error) {
|
|
618
|
+
this.fail(error);
|
|
619
|
+
}
|
|
620
|
+
} else if (message.kind === "request") {
|
|
621
|
+
if (this.incoming.has(message.id)) {
|
|
622
|
+
this.fail(new Error("Duplicate task request identifier"));
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
const controller = new AbortController();
|
|
626
|
+
this.incoming.set(message.id, controller);
|
|
627
|
+
void Promise.resolve().then(() => {
|
|
628
|
+
controller.signal.throwIfAborted();
|
|
629
|
+
return this.options.handleRequest(message.operation, message.value, controller.signal);
|
|
630
|
+
}).then((value) => {
|
|
631
|
+
if (!controller.signal.aborted && !this.failure) {
|
|
632
|
+
this.send({ source: "math.gl/tasks", kind: "result", id: message.id, value }, this.options.getResultTransferList?.(value, message.value));
|
|
633
|
+
}
|
|
634
|
+
}).catch((reason) => {
|
|
635
|
+
if (!controller.signal.aborted && !this.failure) {
|
|
636
|
+
this.send({
|
|
637
|
+
source: "math.gl/tasks",
|
|
638
|
+
kind: "error",
|
|
639
|
+
id: message.id,
|
|
640
|
+
error: {
|
|
641
|
+
name: reason instanceof Error ? reason.name : "Error",
|
|
642
|
+
message: reason instanceof Error ? reason.message : String(reason)
|
|
643
|
+
}
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
}).finally(() => this.incoming.delete(message.id));
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
/** Reject all outstanding calls with a common cause and abort incoming callbacks. */
|
|
650
|
+
close(reason = new Error("Task channel closed")) {
|
|
651
|
+
if (this.failure)
|
|
652
|
+
return;
|
|
653
|
+
this.failure = { reason };
|
|
654
|
+
for (const pending2 of this.pending.values()) {
|
|
655
|
+
pending2.cleanup();
|
|
656
|
+
pending2.reject(reason);
|
|
657
|
+
}
|
|
658
|
+
this.pending.clear();
|
|
659
|
+
for (const controller of this.incoming.values())
|
|
660
|
+
controller.abort(reason);
|
|
661
|
+
this.incoming.clear();
|
|
662
|
+
}
|
|
663
|
+
send(message, transfer = []) {
|
|
664
|
+
if (this.failure)
|
|
665
|
+
return;
|
|
666
|
+
try {
|
|
667
|
+
this.options.send(message, transfer);
|
|
668
|
+
} catch (error) {
|
|
669
|
+
this.fail(error);
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
/** Invalidate the channel and notify the peer when the transport still works. */
|
|
673
|
+
fail(reason) {
|
|
674
|
+
if (this.failure)
|
|
675
|
+
return;
|
|
676
|
+
this.close(reason);
|
|
677
|
+
try {
|
|
678
|
+
this.options.send({
|
|
679
|
+
source: "math.gl/tasks",
|
|
680
|
+
kind: "failure",
|
|
681
|
+
id: 0,
|
|
682
|
+
error: {
|
|
683
|
+
name: reason instanceof Error ? reason.name : "Error",
|
|
684
|
+
message: reason instanceof Error ? reason.message : String(reason)
|
|
685
|
+
}
|
|
686
|
+
}, []);
|
|
687
|
+
} catch {
|
|
688
|
+
}
|
|
689
|
+
this.options.onFailure?.(reason);
|
|
690
|
+
}
|
|
691
|
+
};
|
|
692
|
+
|
|
693
|
+
// ../../node_modules/@math.gl/tasks/dist/tasks/task-runtime.js
|
|
550
694
|
function assertPayload(value) {
|
|
551
695
|
if (!value || typeof value !== "object" || Object.getPrototypeOf(value) !== Object.prototype) {
|
|
552
696
|
throw new TypeError("Task payloads must be plain objects with named fields");
|
|
553
697
|
}
|
|
554
698
|
}
|
|
699
|
+
function clonePayload(value, ownership = "copy") {
|
|
700
|
+
assertPayload(value);
|
|
701
|
+
if (!["copy", "transfer", "share"].includes(ownership))
|
|
702
|
+
throw new TypeError("Invalid input ownership");
|
|
703
|
+
const transfer = getTransferList(value);
|
|
704
|
+
if (ownership === "share" && transfer.length)
|
|
705
|
+
throw new TypeError("Share requires shared storage");
|
|
706
|
+
return structuredClone(value, {
|
|
707
|
+
transfer: ownership === "transfer" ? transfer : []
|
|
708
|
+
});
|
|
709
|
+
}
|
|
555
710
|
function taskContext(state, context = {}) {
|
|
556
711
|
const signal = context.signal ?? new AbortController().signal;
|
|
557
712
|
return {
|
|
558
713
|
state,
|
|
559
714
|
signal,
|
|
715
|
+
requestHost: async (operation, payload, controls) => {
|
|
716
|
+
signal.throwIfAborted();
|
|
717
|
+
if (!context.requestHost)
|
|
718
|
+
throw new Error("No host request handler configured");
|
|
719
|
+
return context.requestHost(operation, payload, controls);
|
|
720
|
+
},
|
|
721
|
+
emitHost: (operation, payload) => {
|
|
722
|
+
signal.throwIfAborted();
|
|
723
|
+
context.emitHost?.(operation, payload);
|
|
724
|
+
},
|
|
560
725
|
throwIfAborted: () => {
|
|
561
726
|
signal.throwIfAborted();
|
|
562
727
|
context.throwIfAborted?.();
|
|
@@ -621,6 +786,69 @@
|
|
|
621
786
|
throw new Error("A task is already installed in this worker");
|
|
622
787
|
installed = true;
|
|
623
788
|
const runtime = new TaskRuntime(task);
|
|
789
|
+
let channelStream;
|
|
790
|
+
const channel = new TaskChannel({
|
|
791
|
+
getResultTransferList: (value, request) => request.outputOwnership === "transfer" ? getTransferList(value) : [],
|
|
792
|
+
send: (message, transfer) => {
|
|
793
|
+
const snapshot = structuredClone(message, { transfer });
|
|
794
|
+
void WorkerBody.postMessage("task-channel", snapshot).catch((reason) => channel.fail(reason));
|
|
795
|
+
},
|
|
796
|
+
handleRequest: async (operation, value, signal) => {
|
|
797
|
+
const request = value;
|
|
798
|
+
const context = {
|
|
799
|
+
signal,
|
|
800
|
+
reportProgress: (progress) => channel.emit("task:progress", { id: request.progressId, progress }),
|
|
801
|
+
requestHost: (operation2, payload, controls = {}) => {
|
|
802
|
+
const request2 = {
|
|
803
|
+
operation: operation2,
|
|
804
|
+
payload: clonePayload(payload, controls.inputOwnership),
|
|
805
|
+
outputOwnership: controls.outputOwnership ?? "copy"
|
|
806
|
+
};
|
|
807
|
+
return channel.request("task:host-request", request2, signal, getTransferList(request2));
|
|
808
|
+
},
|
|
809
|
+
emitHost: (operation2, payload) => channel.emit("task:host-event", { operation: operation2, payload, id: request.progressId })
|
|
810
|
+
};
|
|
811
|
+
switch (operation) {
|
|
812
|
+
case "initialize":
|
|
813
|
+
return runtime.initialize(request.input, context);
|
|
814
|
+
case "process":
|
|
815
|
+
return runtime.process(request.input, request.options, context);
|
|
816
|
+
case "stream-open": {
|
|
817
|
+
if (channelStream)
|
|
818
|
+
throw new Error("A task stream is already open");
|
|
819
|
+
async function* inputs() {
|
|
820
|
+
while (true) {
|
|
821
|
+
const result = await channel.request("task:next-input", { outputOwnership: "transfer" }, signal);
|
|
822
|
+
if (result.done)
|
|
823
|
+
return;
|
|
824
|
+
yield result.value;
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
channelStream = runtime.stream(inputs(), request.options, context)[Symbol.asyncIterator]();
|
|
828
|
+
return {};
|
|
829
|
+
}
|
|
830
|
+
case "stream-next":
|
|
831
|
+
if (!channelStream)
|
|
832
|
+
throw new Error("No active task stream");
|
|
833
|
+
return channelStream.next();
|
|
834
|
+
case "stream-close":
|
|
835
|
+
try {
|
|
836
|
+
await channelStream?.return?.();
|
|
837
|
+
} finally {
|
|
838
|
+
channelStream = void 0;
|
|
839
|
+
}
|
|
840
|
+
return {};
|
|
841
|
+
case "destroy":
|
|
842
|
+
return runtime.destroy();
|
|
843
|
+
default:
|
|
844
|
+
throw new Error("Unknown task channel operation");
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
});
|
|
848
|
+
await WorkerBody.addEventListener((type, payload) => {
|
|
849
|
+
if (type === "task-channel")
|
|
850
|
+
channel.receive(payload);
|
|
851
|
+
});
|
|
624
852
|
let streamOptions = {};
|
|
625
853
|
return createWorker(async (request, _options, context) => {
|
|
626
854
|
switch (request.operation) {
|