@loaders.gl/core 5.0.0-beta.1 → 5.0.0-beta.2

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.
Files changed (117) hide show
  1. package/README.md +3 -1
  2. package/dist/cluster-source.cjs +7228 -0
  3. package/dist/cluster-source.cjs.map +6 -0
  4. package/dist/cluster-source.d.ts +2 -0
  5. package/dist/cluster-source.d.ts.map +1 -0
  6. package/dist/cluster-source.js +2 -0
  7. package/dist/cluster-source.js.map +1 -0
  8. package/dist/dist.dev.js +894 -273
  9. package/dist/dist.min.js +3 -3
  10. package/dist/federated-table-scan-source.cjs +2677 -0
  11. package/dist/federated-table-scan-source.cjs.map +6 -0
  12. package/dist/federated-table-scan-source.d.ts +2 -0
  13. package/dist/federated-table-scan-source.d.ts.map +1 -0
  14. package/dist/federated-table-scan-source.js +2 -0
  15. package/dist/federated-table-scan-source.js.map +1 -0
  16. package/dist/index.cjs +12 -1045
  17. package/dist/index.cjs.map +3 -3
  18. package/dist/lib/init.js +1 -1
  19. package/dist/loader-utils/index.cjs +43 -1331
  20. package/dist/loader-utils/index.cjs.map +3 -3
  21. package/dist/loader-utils/json-loader.js +1 -1
  22. package/dist/loader-utils/lib/log-utils/log.js +1 -1
  23. package/dist/null-loader.js +1 -1
  24. package/dist/null-worker-node.js +169 -79
  25. package/dist/null-worker.js +166 -55
  26. package/dist/polyfills/images/encode-image-node.d.ts +18 -15
  27. package/dist/polyfills/images/encode-image-node.d.ts.map +1 -1
  28. package/dist/polyfills/images/encode-image-node.js +19 -33
  29. package/dist/polyfills/images/encode-image-node.js.map +1 -1
  30. package/dist/polyfills/images/image-codecs-node.d.ts +2 -6
  31. package/dist/polyfills/images/image-codecs-node.d.ts.map +1 -1
  32. package/dist/polyfills/images/image-codecs-node.js +2 -24
  33. package/dist/polyfills/images/image-codecs-node.js.map +1 -1
  34. package/dist/polyfills/images/load-sharp.d.ts +3 -0
  35. package/dist/polyfills/images/load-sharp.d.ts.map +1 -0
  36. package/dist/polyfills/images/load-sharp.js +11 -0
  37. package/dist/polyfills/images/load-sharp.js.map +1 -0
  38. package/dist/polyfills/images/node-image-bitmap.d.ts +1 -1
  39. package/dist/polyfills/images/node-image-bitmap.js +1 -1
  40. package/dist/polyfills/images/node-image-formats.d.ts +1 -1
  41. package/dist/polyfills/images/node-image-formats.d.ts.map +1 -1
  42. package/dist/polyfills/images/node-image-formats.js +10 -4
  43. package/dist/polyfills/images/node-image-formats.js.map +1 -1
  44. package/dist/polyfills/images/parse-image-node.d.ts +10 -2
  45. package/dist/polyfills/images/parse-image-node.d.ts.map +1 -1
  46. package/dist/polyfills/images/parse-image-node.js +20 -32
  47. package/dist/polyfills/images/parse-image-node.js.map +1 -1
  48. package/dist/polyfills/index.cjs +73 -149
  49. package/dist/vector-table-scan-source.cjs +1703 -0
  50. package/dist/vector-table-scan-source.cjs.map +6 -0
  51. package/dist/vector-table-scan-source.d.ts +2 -0
  52. package/dist/vector-table-scan-source.d.ts.map +1 -0
  53. package/dist/vector-table-scan-source.js +2 -0
  54. package/dist/vector-table-scan-source.js.map +1 -0
  55. package/dist/worker-utils/index.cjs +72 -1225
  56. package/dist/worker-utils/index.cjs.map +3 -3
  57. package/dist/worker-utils/lib/async-queue/async-queue.d.ts +1 -31
  58. package/dist/worker-utils/lib/async-queue/async-queue.d.ts.map +1 -1
  59. package/dist/worker-utils/lib/async-queue/async-queue.js +1 -87
  60. package/dist/worker-utils/lib/async-queue/async-queue.js.map +1 -1
  61. package/dist/worker-utils/lib/env-utils/version.js +1 -1
  62. package/dist/worker-utils/lib/worker-api/create-worker.d.ts +1 -8
  63. package/dist/worker-utils/lib/worker-api/create-worker.d.ts.map +1 -1
  64. package/dist/worker-utils/lib/worker-api/create-worker.js +1 -157
  65. package/dist/worker-utils/lib/worker-api/create-worker.js.map +1 -1
  66. package/dist/worker-utils/lib/worker-api/process-on-worker.d.ts +2 -49
  67. package/dist/worker-utils/lib/worker-api/process-on-worker.d.ts.map +1 -1
  68. package/dist/worker-utils/lib/worker-api/process-on-worker.js +1 -345
  69. package/dist/worker-utils/lib/worker-api/process-on-worker.js.map +1 -1
  70. package/dist/worker-utils/lib/worker-farm/worker-body.d.ts +1 -19
  71. package/dist/worker-utils/lib/worker-farm/worker-body.d.ts.map +1 -1
  72. package/dist/worker-utils/lib/worker-farm/worker-body.js +1 -127
  73. package/dist/worker-utils/lib/worker-farm/worker-body.js.map +1 -1
  74. package/dist/worker-utils/lib/worker-farm/worker-farm.d.ts +1 -57
  75. package/dist/worker-utils/lib/worker-farm/worker-farm.d.ts.map +1 -1
  76. package/dist/worker-utils/lib/worker-farm/worker-farm.js +1 -112
  77. package/dist/worker-utils/lib/worker-farm/worker-farm.js.map +1 -1
  78. package/dist/worker-utils/lib/worker-farm/worker-job.d.ts +1 -33
  79. package/dist/worker-utils/lib/worker-farm/worker-job.d.ts.map +1 -1
  80. package/dist/worker-utils/lib/worker-farm/worker-job.js +1 -70
  81. package/dist/worker-utils/lib/worker-farm/worker-job.js.map +1 -1
  82. package/dist/worker-utils/lib/worker-farm/worker-pool.d.ts +1 -93
  83. package/dist/worker-utils/lib/worker-farm/worker-pool.d.ts.map +1 -1
  84. package/dist/worker-utils/lib/worker-farm/worker-pool.js +1 -242
  85. package/dist/worker-utils/lib/worker-farm/worker-pool.js.map +1 -1
  86. package/dist/worker-utils/lib/worker-farm/worker-thread.d.ts +1 -66
  87. package/dist/worker-utils/lib/worker-farm/worker-thread.d.ts.map +1 -1
  88. package/dist/worker-utils/lib/worker-farm/worker-thread.js +1 -171
  89. package/dist/worker-utils/lib/worker-farm/worker-thread.js.map +1 -1
  90. package/dist/worker-utils/null-worker-node.js +234 -144
  91. package/dist/worker-utils/null-worker-node.js.map +4 -4
  92. package/dist/worker-utils/null-worker.js +232 -121
  93. package/dist/worker-utils/null-worker.js.map +4 -4
  94. package/dist/worker-utils/types.d.ts +1 -99
  95. package/dist/worker-utils/types.d.ts.map +1 -1
  96. package/package.json +27 -29
  97. package/src/cluster-source.ts +1 -0
  98. package/src/federated-table-scan-source.ts +1 -0
  99. package/src/polyfills/README.md +2 -2
  100. package/src/polyfills/images/encode-image-node.ts +44 -37
  101. package/src/polyfills/images/image-codecs-node.ts +2 -37
  102. package/src/polyfills/images/load-sharp.ts +13 -0
  103. package/src/polyfills/images/node-image-bitmap.ts +1 -1
  104. package/src/polyfills/images/node-image-formats.ts +10 -4
  105. package/src/polyfills/images/parse-image-node.ts +31 -40
  106. package/src/vector-table-scan-source.ts +1 -0
  107. package/src/worker-utils/lib/async-queue/async-queue.ts +1 -96
  108. package/src/worker-utils/lib/worker-api/create-worker.ts +1 -201
  109. package/src/worker-utils/lib/worker-api/process-on-worker.ts +8 -464
  110. package/src/worker-utils/lib/worker-farm/worker-body.ts +1 -141
  111. package/src/worker-utils/lib/worker-farm/worker-farm.ts +1 -140
  112. package/src/worker-utils/lib/worker-farm/worker-job.ts +1 -81
  113. package/src/worker-utils/lib/worker-farm/worker-pool.ts +1 -312
  114. package/src/worker-utils/lib/worker-farm/worker-thread.ts +1 -202
  115. package/src/worker-utils/types.ts +14 -144
  116. package/src/polyfills/images/encode-image.node.ts.disabled +0 -41
  117. package/src/polyfills/images/parse-image.node.ts.disabled +0 -55
package/dist/index.cjs CHANGED
@@ -216,1044 +216,11 @@ var isMobile = typeof window !== "undefined" && typeof window.orientation !== "u
216
216
  var matches2 = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
217
217
  var nodeVersion2 = matches2 && parseFloat(matches2[1]) || 0;
218
218
 
219
- // src/worker-utils/lib/worker-farm/worker-job.ts
220
- var WorkerJob = class {
221
- name;
222
- workerThread;
223
- isRunning = true;
224
- /** Promise that resolves when Job is done */
225
- result;
226
- _resolve = () => {
227
- };
228
- _reject = () => {
229
- };
230
- constructor(jobName, workerThread) {
231
- this.name = jobName;
232
- this.workerThread = workerThread;
233
- this.result = new Promise((resolve2, reject) => {
234
- this._resolve = resolve2;
235
- this._reject = reject;
236
- });
237
- }
238
- /**
239
- * Send a message to the job's worker thread
240
- * @param data any data structure, ideally consisting mostly of transferrable objects
241
- */
242
- postMessage(type, payload) {
243
- if (!this.isRunning) return;
244
- this.workerThread.postMessage({
245
- source: "loaders.gl",
246
- // Lets worker ignore unrelated messages
247
- type,
248
- payload
249
- });
250
- }
251
- /**
252
- * Call to resolve the `result` Promise with the supplied value
253
- */
254
- done(value) {
255
- if (!this.isRunning) {
256
- return;
257
- }
258
- this.isRunning = false;
259
- this._resolve(value);
260
- }
261
- /**
262
- * Call to reject the `result` Promise with the supplied error
263
- */
264
- error(error) {
265
- if (!this.isRunning) {
266
- return;
267
- }
268
- this.isRunning = false;
269
- this._reject(error);
270
- }
271
- /**
272
- * Terminates the worker executing this job and rejects its result.
273
- * @param reason Abort reason supplied by the caller, or a cross-runtime `AbortError`.
274
- */
275
- abort(reason) {
276
- if (!this.isRunning) {
277
- return;
278
- }
279
- this.workerThread.destroy();
280
- this.error(
281
- arguments.length ? reason : createAbortError(`Worker job "${this.name}" was aborted`)
282
- );
283
- }
284
- };
285
- function createAbortError(message) {
286
- const error = new Error(message);
287
- error.name = "AbortError";
288
- return error;
289
- }
290
-
291
- // src/worker-utils/lib/node/worker_threads-browser.ts
292
- var NodeWorker = class {
293
- /** Restores the native worker constructor when this browser shim is embedded in a Node bundle. */
294
- constructor(...arguments_) {
295
- var _a;
296
- const runtimeProcess = globalThis.process;
297
- const WorkerConstructor = (_a = runtimeProcess == null ? void 0 : runtimeProcess.getBuiltinModule) == null ? void 0 : _a.call(runtimeProcess, "node:worker_threads").Worker;
298
- if (WorkerConstructor) {
299
- return new WorkerConstructor(...arguments_);
300
- }
301
- }
302
- /** No-op browser fallback matching the native Worker API. */
303
- terminate() {
304
- }
305
- };
306
-
307
- // src/worker-utils/lib/worker-utils/get-loadable-worker-url.ts
308
- var workerURLCache = /* @__PURE__ */ new Map();
309
- function getLoadableWorkerURL(props) {
310
- assert2(props.source && !props.url || !props.source && props.url);
311
- let workerURL = workerURLCache.get(props.source || props.url);
312
- if (!workerURL) {
313
- if (props.url) {
314
- workerURL = getLoadableWorkerURLFromURL(props.url);
315
- workerURLCache.set(props.url, workerURL);
316
- }
317
- if (props.source) {
318
- workerURL = getLoadableWorkerURLFromSource(props.source);
319
- workerURLCache.set(props.source, workerURL);
320
- }
321
- }
322
- assert2(workerURL);
323
- return workerURL;
324
- }
325
- function getLoadableWorkerURLFromURL(url) {
326
- if (!url.startsWith("http")) {
327
- return url;
328
- }
329
- const workerSource = buildScriptSource(url);
330
- return getLoadableWorkerURLFromSource(workerSource);
331
- }
332
- function getLoadableWorkerURLFromSource(workerSource) {
333
- const blob = new Blob([workerSource], { type: "application/javascript" });
334
- return URL.createObjectURL(blob);
335
- }
336
- function buildScriptSource(workerUrl) {
337
- return `try {
338
- importScripts('${workerUrl}');
339
- } catch (error) {
340
- console.error(error);
341
- throw error;
342
- }`;
343
- }
344
-
345
- // src/worker-utils/lib/worker-utils/get-transfer-list.ts
346
- function getTransferList(object, recursive = true, transfers) {
347
- const transfersSet = transfers || /* @__PURE__ */ new Set();
348
- if (!object) {
349
- } else if (isTransferable(object)) {
350
- transfersSet.add(object);
351
- } else if (isTransferable(object.buffer)) {
352
- transfersSet.add(object.buffer);
353
- } else if (ArrayBuffer.isView(object)) {
354
- } else if (recursive && typeof object === "object") {
355
- for (const key in object) {
356
- getTransferList(object[key], recursive, transfersSet);
357
- }
358
- }
359
- return transfers === void 0 ? Array.from(transfersSet) : [];
360
- }
361
- function isTransferable(object) {
362
- if (!object) {
363
- return false;
364
- }
365
- if (object instanceof ArrayBuffer) {
366
- return true;
367
- }
368
- if (typeof MessagePort !== "undefined" && object instanceof MessagePort) {
369
- return true;
370
- }
371
- if (typeof ImageBitmap !== "undefined" && object instanceof ImageBitmap) {
372
- return true;
373
- }
374
- if (typeof OffscreenCanvas !== "undefined" && object instanceof OffscreenCanvas) {
375
- return true;
376
- }
377
- return false;
378
- }
379
- function getTransferListForWriter(object) {
380
- if (object === null) {
381
- return {};
382
- }
383
- const clone = Object.assign({}, object);
384
- Object.keys(clone).forEach((key) => {
385
- if (typeof object[key] === "object" && !ArrayBuffer.isView(object[key]) && !(object[key] instanceof Array)) {
386
- clone[key] = getTransferListForWriter(object[key]);
387
- } else if (typeof clone[key] === "function" || clone[key] instanceof RegExp) {
388
- clone[key] = {};
389
- } else {
390
- clone[key] = object[key];
391
- }
392
- });
393
- return clone;
394
- }
395
-
396
- // src/worker-utils/lib/worker-farm/worker-thread.ts
397
- var NOOP = () => {
398
- };
399
- var WorkerThread = class {
400
- name;
401
- source;
402
- url;
403
- /** Lazily resolves the classic worker URL used as a fallback. */
404
- getUrl;
405
- /** Creates a browser Worker directly. */
406
- loadWorker;
407
- terminated = false;
408
- worker;
409
- onMessage;
410
- onError;
411
- _loadableURL = "";
412
- /** Checks if workers are supported on this platform */
413
- static isSupported() {
414
- return typeof Worker !== "undefined" && isBrowser2 || typeof NodeWorker !== "undefined" && !isBrowser2;
415
- }
416
- constructor(props) {
417
- const { name, source, url, getUrl, loadWorker } = props;
418
- assert2(source || url || getUrl || loadWorker);
419
- this.name = name;
420
- this.source = source;
421
- this.url = url;
422
- this.getUrl = getUrl;
423
- this.loadWorker = loadWorker;
424
- this.onMessage = NOOP;
425
- this.onError = (error) => console.log(error);
426
- this.worker = isBrowser2 ? this._createBrowserWorker() : this._createNodeWorker();
427
- }
428
- /**
429
- * Terminate this worker thread
430
- * @note Can free up significant memory
431
- */
432
- destroy() {
433
- this.onMessage = NOOP;
434
- this.onError = NOOP;
435
- this.worker.terminate();
436
- this.terminated = true;
437
- }
438
- /** Keeps this worker from preventing Node.js process exit while idle. */
439
- unref() {
440
- if (!isBrowser2 && typeof this.worker.unref === "function") {
441
- this.worker.unref();
442
- }
443
- }
444
- /** Keeps this worker alive while it is actively processing a job. */
445
- ref() {
446
- if (!isBrowser2 && typeof this.worker.ref === "function") {
447
- this.worker.ref();
448
- }
449
- }
450
- get isRunning() {
451
- return Boolean(this.onMessage);
452
- }
453
- /**
454
- * Send a message to this worker thread
455
- * @param data any data structure, ideally consisting mostly of transferrable objects
456
- * @param transferList If not supplied, calculated automatically by traversing data
457
- */
458
- postMessage(data, transferList) {
459
- transferList = transferList || getTransferList(data);
460
- this.worker.postMessage(data, transferList);
461
- }
462
- // PRIVATE
463
- /**
464
- * Generate a standard Error from an ErrorEvent
465
- * @param event
466
- */
467
- _getErrorFromErrorEvent(event) {
468
- let message = "Failed to load ";
469
- message += `worker ${this.name} from ${this.url || "built-in worker factory"}. `;
470
- if (event.message) {
471
- message += `${event.message} in `;
472
- }
473
- if (event.lineno) {
474
- message += `:${event.lineno}:${event.colno}`;
475
- }
476
- return new Error(message);
477
- }
478
- /**
479
- * Creates a worker thread on the browser
480
- */
481
- _createBrowserWorker() {
482
- var _a;
483
- if (this.loadWorker) {
484
- try {
485
- const worker2 = this.loadWorker();
486
- if (worker2) {
487
- return this._initializeBrowserWorker(worker2);
488
- }
489
- } catch (error) {
490
- if (!this.source && !this.url && !this.getUrl) {
491
- throw error;
492
- }
493
- }
494
- }
495
- const url = this.url || ((_a = this.getUrl) == null ? void 0 : _a.call(this));
496
- this._loadableURL = getLoadableWorkerURL({ source: this.source, url });
497
- const worker = new Worker(this._loadableURL, { name: this.name });
498
- return this._initializeBrowserWorker(worker);
499
- }
500
- /** Attaches protocol handlers to a browser worker. */
501
- _initializeBrowserWorker(worker) {
502
- worker.onmessage = (event) => {
503
- if (!event.data) {
504
- this.onError(new Error("No data received"));
505
- } else {
506
- this.onMessage(event.data);
507
- }
508
- };
509
- worker.onerror = (error) => {
510
- this.onError(this._getErrorFromErrorEvent(error));
511
- this.terminated = true;
512
- };
513
- worker.onmessageerror = (event) => console.error(event);
514
- return worker;
515
- }
516
- /**
517
- * Creates a worker thread in node.js
518
- * @todo https://nodejs.org/api/async_hooks.html#async-resource-worker-pool
519
- */
520
- _createNodeWorker() {
521
- let worker;
522
- if (this.url) {
523
- const absolute = this.url.includes(":/") || this.url.startsWith("/");
524
- const url = absolute ? this.url : `./${this.url}`;
525
- const workerUrl = url.startsWith("file:") ? new URL(url) : url;
526
- const type = this.url.endsWith(".ts") || this.url.endsWith(".mjs") ? "module" : "commonjs";
527
- worker = new NodeWorker(workerUrl, { eval: false, type });
528
- } else if (this.source) {
529
- worker = new NodeWorker(this.source, { eval: true });
530
- } else {
531
- throw new Error("no worker");
532
- }
533
- worker.on("message", (data) => {
534
- this.onMessage(data);
535
- });
536
- worker.on("error", (error) => {
537
- this.onError(error);
538
- });
539
- worker.on("exit", (_code) => {
540
- });
541
- return worker;
542
- }
543
- };
544
-
545
- // src/worker-utils/lib/worker-farm/worker-pool.ts
546
- var WorkerPool = class {
547
- name = "unnamed";
548
- source;
549
- // | Function;
550
- url;
551
- /** Lazily resolves a classic worker fallback URL. */
552
- getUrl;
553
- /** Creates a browser Worker directly. */
554
- loadWorker;
555
- maxConcurrency = 1;
556
- maxMobileConcurrency = 1;
557
- onDebug = () => {
558
- };
559
- reuseWorkers = true;
560
- props = {};
561
- jobQueue = [];
562
- idleQueue = [];
563
- activeJobs = /* @__PURE__ */ new Set();
564
- count = 0;
565
- isDestroyed = false;
566
- /** Checks if workers are supported on this platform */
567
- static isSupported() {
568
- return WorkerThread.isSupported();
569
- }
570
- /**
571
- * @param processor - worker function
572
- * @param maxConcurrency - max count of workers
573
- */
574
- constructor(props) {
575
- this.source = props.source;
576
- this.url = props.url;
577
- this.getUrl = props.getUrl;
578
- this.loadWorker = props.loadWorker;
579
- this.setProps(props);
580
- }
581
- /**
582
- * Terminates all workers in the pool and aborts active jobs.
583
- * @param reason Optional error delivered to active jobs.
584
- * @note Can free up significant memory
585
- */
586
- destroy(reason = new Error("Worker pool was destroyed")) {
587
- this.isDestroyed = true;
588
- this.activeJobs.forEach((job) => job.abort(reason));
589
- const queuedJobs = this.jobQueue.splice(0);
590
- queuedJobs.forEach((queuedJob) => {
591
- queuedJob.removeAbortListener();
592
- queuedJob.onReject(reason);
593
- });
594
- this.idleQueue.forEach((worker) => worker.destroy());
595
- this.isDestroyed = true;
596
- }
597
- setProps(props) {
598
- this.props = { ...this.props, ...props };
599
- if (props.name !== void 0) {
600
- this.name = props.name;
601
- }
602
- if (props.maxConcurrency !== void 0) {
603
- this.maxConcurrency = props.maxConcurrency;
604
- }
605
- if (props.maxMobileConcurrency !== void 0) {
606
- this.maxMobileConcurrency = props.maxMobileConcurrency;
607
- }
608
- if (props.reuseWorkers !== void 0) {
609
- this.reuseWorkers = props.reuseWorkers;
610
- }
611
- if (props.onDebug !== void 0) {
612
- this.onDebug = props.onDebug;
613
- }
614
- }
615
- async startJob(name, onMessage2 = (job, type, data) => job.done(data), onError = (job, error) => job.error(error), signal) {
616
- if (signal == null ? void 0 : signal.aborted) {
617
- throw signal.reason;
618
- }
619
- if (this.isDestroyed) {
620
- return Promise.reject(new Error("Worker pool was destroyed"));
621
- }
622
- const startPromise = new Promise((onStart, onReject) => {
623
- const abortQueuedJob = () => {
624
- const index = this.jobQueue.indexOf(queuedJob);
625
- if (index >= 0) {
626
- this.jobQueue.splice(index, 1);
627
- queuedJob.removeAbortListener();
628
- onReject(signal == null ? void 0 : signal.reason);
629
- }
630
- };
631
- const queuedJob = {
632
- name,
633
- onMessage: onMessage2,
634
- onError,
635
- onStart,
636
- onReject,
637
- signal,
638
- removeAbortListener: () => signal == null ? void 0 : signal.removeEventListener("abort", abortQueuedJob)
639
- };
640
- this.jobQueue.push(queuedJob);
641
- signal == null ? void 0 : signal.addEventListener("abort", abortQueuedJob, { once: true });
642
- return this;
643
- });
644
- this._startQueuedJob();
645
- return await startPromise;
646
- }
647
- // PRIVATE
648
- /**
649
- * Starts first queued job if worker is available or can be created
650
- * Called when job is started and whenever a worker returns to the idleQueue
651
- */
652
- async _startQueuedJob() {
653
- var _a, _b, _c;
654
- if (!this.jobQueue.length) {
655
- return;
656
- }
657
- let workerThread;
658
- try {
659
- workerThread = this._getAvailableWorker();
660
- } catch (error) {
661
- const queuedJob2 = this.jobQueue.shift();
662
- queuedJob2 == null ? void 0 : queuedJob2.removeAbortListener();
663
- queuedJob2 == null ? void 0 : queuedJob2.onReject(error);
664
- void this._startQueuedJob();
665
- return;
666
- }
667
- if (!workerThread) {
668
- return;
669
- }
670
- const queuedJob = this.jobQueue.shift();
671
- if (queuedJob) {
672
- this.onDebug({
673
- message: "Starting job",
674
- name: queuedJob.name,
675
- workerThread,
676
- backlog: this.jobQueue.length
677
- });
678
- const job = new WorkerJob(queuedJob.name, workerThread);
679
- queuedJob.removeAbortListener();
680
- const abortJob = () => {
681
- var _a2;
682
- return job.abort((_a2 = queuedJob.signal) == null ? void 0 : _a2.reason);
683
- };
684
- (_a = queuedJob.signal) == null ? void 0 : _a.addEventListener("abort", abortJob, { once: true });
685
- if ((_b = queuedJob.signal) == null ? void 0 : _b.aborted) abortJob();
686
- this.activeJobs.add(job);
687
- workerThread.ref();
688
- workerThread.onMessage = (data) => {
689
- if (job.isRunning) queuedJob.onMessage(job, data.type, data.payload);
690
- };
691
- workerThread.onError = (error) => queuedJob.onError(job, error);
692
- queuedJob.onStart(job);
693
- try {
694
- await job.result;
695
- } catch {
696
- } finally {
697
- (_c = queuedJob.signal) == null ? void 0 : _c.removeEventListener("abort", abortJob);
698
- this.activeJobs.delete(job);
699
- this.returnWorkerToQueue(workerThread);
700
- }
701
- } else {
702
- this.returnWorkerToQueue(workerThread);
703
- }
704
- }
705
- /**
706
- * Returns a worker to the idle queue
707
- * Destroys the worker if
708
- * - pool is destroyed
709
- * - if this pool doesn't reuse workers
710
- * - if maxConcurrency has been lowered
711
- * @param worker
712
- */
713
- returnWorkerToQueue(worker) {
714
- const shouldDestroyWorker = (
715
- // Aborted jobs terminate their worker immediately.
716
- worker.terminated || // If the pool is destroyed, there is no reason to keep the worker around
717
- this.isDestroyed || // If the app has disabled worker reuse, any completed workers should be destroyed
718
- !this.reuseWorkers || // If concurrency has been lowered, this worker might be surplus to requirements
719
- this.count > this._getMaxConcurrency()
720
- );
721
- if (shouldDestroyWorker) {
722
- if (!worker.terminated) {
723
- worker.destroy();
724
- }
725
- this.count--;
726
- } else {
727
- worker.unref();
728
- this.idleQueue.push(worker);
729
- }
730
- if (!this.isDestroyed) {
731
- this._startQueuedJob();
732
- }
733
- }
734
- /**
735
- * Returns idle worker or creates new worker if maxConcurrency has not been reached
736
- */
737
- _getAvailableWorker() {
738
- if (this.idleQueue.length > 0) {
739
- return this.idleQueue.shift() || null;
740
- }
741
- if (this.count < this._getMaxConcurrency()) {
742
- this.count++;
743
- const name = `${this.name.toLowerCase()} (#${this.count} of ${this.maxConcurrency})`;
744
- try {
745
- return new WorkerThread({
746
- name,
747
- source: this.source,
748
- url: this.url,
749
- getUrl: this.getUrl,
750
- loadWorker: this.loadWorker
751
- });
752
- } catch (error) {
753
- this.count--;
754
- throw error;
755
- }
756
- }
757
- return null;
758
- }
759
- _getMaxConcurrency() {
760
- return isMobile ? this.maxMobileConcurrency : this.maxConcurrency;
761
- }
762
- };
763
-
764
219
  // src/worker-utils/lib/worker-farm/worker-farm.ts
765
- var DEFAULT_PROPS = {
766
- maxConcurrency: 3,
767
- maxMobileConcurrency: 1,
768
- reuseWorkers: true,
769
- onDebug: () => {
770
- }
771
- };
772
- var loadWorkerIds = /* @__PURE__ */ new WeakMap();
773
- var nextLoadWorkerId = 1;
774
- var WorkerFarm = class _WorkerFarm {
775
- props;
776
- workerPools = /* @__PURE__ */ new Map();
777
- // singleton
778
- static _workerFarm;
779
- /** Checks if workers are supported on this platform */
780
- static isSupported() {
781
- return WorkerThread.isSupported();
782
- }
783
- /** Get the singleton instance of the global worker farm */
784
- static getWorkerFarm(props = {}) {
785
- _WorkerFarm._workerFarm = _WorkerFarm._workerFarm || new _WorkerFarm({});
786
- _WorkerFarm._workerFarm.setProps(props);
787
- return _WorkerFarm._workerFarm;
788
- }
789
- /** get global instance with WorkerFarm.getWorkerFarm() */
790
- constructor(props) {
791
- this.props = { ...DEFAULT_PROPS };
792
- this.setProps(props);
793
- this.workerPools = /* @__PURE__ */ new Map();
794
- }
795
- /**
796
- * Terminate all workers in the farm and abort active jobs.
797
- * @param reason Optional error delivered to active jobs.
798
- * @note Can free up significant memory
799
- */
800
- destroy(reason) {
801
- for (const workerPool of this.workerPools.values()) {
802
- workerPool.destroy(reason);
803
- }
804
- this.workerPools = /* @__PURE__ */ new Map();
805
- }
806
- /**
807
- * Set props used when initializing worker pools
808
- * @param props
809
- */
810
- setProps(props) {
811
- this.props = { ...this.props, ...props };
812
- for (const workerPool of this.workerPools.values()) {
813
- workerPool.setProps(this._getWorkerPoolProps());
814
- }
815
- }
816
- /**
817
- * Returns a worker pool for the specified worker
818
- * @param options Worker target used to identify and initialize the pool.
819
- * @param options.name Worker name used as the base pool identity.
820
- * @param options.url Worker script URL.
821
- * @param options.source Inline worker source.
822
- * @param options.loadWorker Built-in browser worker factory.
823
- * @example
824
- * const job = WorkerFarm.getWorkerFarm().getWorkerPool({name, url}).startJob(...);
825
- */
826
- getWorkerPool(options) {
827
- const { name, source, url, getUrl, loadWorker } = options;
828
- const workerPoolKey = getWorkerPoolKey(options);
829
- let workerPool = this.workerPools.get(workerPoolKey);
830
- if (!workerPool) {
831
- workerPool = new WorkerPool({
832
- name,
833
- source,
834
- url,
835
- getUrl,
836
- loadWorker
837
- });
838
- workerPool.setProps(this._getWorkerPoolProps());
839
- this.workerPools.set(workerPoolKey, workerPool);
840
- }
841
- return workerPool;
842
- }
843
- _getWorkerPoolProps() {
844
- return {
845
- maxConcurrency: this.props.maxConcurrency,
846
- maxMobileConcurrency: this.props.maxMobileConcurrency,
847
- reuseWorkers: this.props.reuseWorkers,
848
- onDebug: this.props.onDebug
849
- };
850
- }
851
- };
852
- function getWorkerPoolKey(options) {
853
- const { name, source, url, urlKey, loadWorker } = options;
854
- const sourceKey = source ? `source:${source}` : "";
855
- const urlKeyPart = url || urlKey ? `url:${url || urlKey}` : "";
856
- const loadWorkerKey = loadWorker ? `loadWorker:${getLoadWorkerId(loadWorker)}` : "";
857
- return [name, sourceKey, urlKeyPart, loadWorkerKey].filter(Boolean).join("|");
858
- }
859
- function getLoadWorkerId(loadWorker) {
860
- let loadWorkerId = loadWorkerIds.get(loadWorker);
861
- if (!loadWorkerId) {
862
- loadWorkerId = nextLoadWorkerId++;
863
- loadWorkerIds.set(loadWorker, loadWorkerId);
864
- }
865
- return loadWorkerId;
866
- }
867
-
868
- // src/worker-utils/lib/async-queue/async-queue.ts
869
- var AsyncQueue = class {
870
- _values;
871
- _settlers;
872
- _closed;
873
- constructor() {
874
- this._values = [];
875
- this._settlers = [];
876
- this._closed = false;
877
- }
878
- /** Return an async iterator for this queue */
879
- [Symbol.asyncIterator]() {
880
- return this;
881
- }
882
- /** Push a new value - the async iterator will yield a promise resolved to this value */
883
- push(value) {
884
- return this.enqueue(value);
885
- }
886
- /**
887
- * Push a new value - the async iterator will yield a promise resolved to this value
888
- * Add an error - the async iterator will yield a promise rejected with this value
889
- */
890
- enqueue(value) {
891
- if (this._closed) {
892
- throw new Error("Closed");
893
- }
894
- if (this._settlers.length > 0) {
895
- if (this._values.length > 0) {
896
- throw new Error("Illegal internal state");
897
- }
898
- const settler = this._settlers.shift();
899
- if (value instanceof Error) {
900
- settler.reject(value);
901
- } else {
902
- settler.resolve({ value });
903
- }
904
- } else {
905
- this._values.push(value);
906
- }
907
- }
908
- /** Indicate that we not waiting for more values - The async iterator will be done */
909
- close() {
910
- while (this._settlers.length > 0) {
911
- const settler = this._settlers.shift();
912
- settler.resolve({ done: true });
913
- }
914
- this._closed = true;
915
- }
916
- // ITERATOR IMPLEMENTATION
917
- /** @returns a Promise for an IteratorResult */
918
- next() {
919
- if (this._values.length > 0) {
920
- const value = this._values.shift();
921
- if (value instanceof Error) {
922
- return Promise.reject(value);
923
- }
924
- return Promise.resolve({ done: false, value });
925
- }
926
- if (this._closed) {
927
- if (this._settlers.length > 0) {
928
- throw new Error("Illegal internal state");
929
- }
930
- return Promise.resolve({ done: true, value: void 0 });
931
- }
932
- return new Promise((resolve2, reject) => {
933
- this._settlers.push({ resolve: resolve2, reject });
934
- });
935
- }
936
- };
937
-
938
- // src/worker-utils/lib/worker-api/get-worker-url.ts
939
- var warnedWorkerVersionFallbacks = /* @__PURE__ */ new Set();
940
- function getWorkerName(worker) {
941
- const warning = worker.version !== VERSION2 ? ` (worker-utils@${VERSION2})` : "";
942
- return `${worker.name}@${worker.version}${warning}`;
943
- }
944
- function getCustomWorkerURL(worker, options = {}) {
945
- var _a, _b;
946
- const workerFile = isBrowser2 ? worker.workerFile || `${worker.id}-worker.js` : worker.workerNode || `${worker.id}-worker-node.js`;
947
- let url = getConfiguredWorkerURL(worker, options);
948
- const workerType = options._workerType || ((_a = options == null ? void 0 : options.core) == null ? void 0 : _a._workerType);
949
- if (!url && workerType === "test") {
950
- if (isBrowser2) {
951
- url = `modules/${worker.module}/dist/${workerFile}`;
952
- } else {
953
- const workerSourceDirectory = worker.module === "core" && ((_b = worker.workerNode) == null ? void 0 : _b.startsWith("worker-utils/")) ? "worker-utils/workers" : "workers";
954
- const workerSourceNode = worker.workerSourceNode || `${workerSourceDirectory}/${worker.id}-worker-node.ts`;
955
- url = `modules/${worker.module}/src/${workerSourceNode}`;
956
- }
957
- }
958
- return url || null;
959
- }
960
- function getConfiguredWorkerURL(worker, options = {}) {
961
- const workerOptions = options[worker.id] || {};
962
- return workerOptions.workerUrl || (worker.id === "compression" ? options.workerUrl : null) || null;
963
- }
964
- function getWorkerURL(worker, options = {}) {
965
- const customWorkerUrl = getCustomWorkerURL(worker, options);
966
- const descriptorWorkerUrl = typeof worker.worker === "string" ? worker.worker : null;
967
- const url = customWorkerUrl || descriptorWorkerUrl || getDefaultWorkerURL(worker, true);
968
- assert2(url);
969
- return url;
970
- }
971
- function getDefaultWorkerURL(worker, warn = false) {
972
- const workerFile = isBrowser2 ? worker.workerFile || `${worker.id}-worker.js` : worker.workerNode || `${worker.id}-worker-node.js`;
973
- let version2 = worker.version;
974
- if (version2 === "latest") {
975
- version2 = NPM_TAG;
976
- }
977
- const versionTag = version2 ? `@${version2}` : "";
978
- const url = `https://unpkg.com/@loaders.gl/${worker.module}${versionTag}/dist/${workerFile}`;
979
- if (warn) {
980
- warnIfUsingNpmTagFallback(worker, url);
981
- }
982
- return url;
983
- }
984
- function warnIfUsingNpmTagFallback(worker, url) {
985
- if (worker.version !== "latest") {
986
- return;
987
- }
988
- const workerId = `${worker.module}:${worker.id}`;
989
- if (warnedWorkerVersionFallbacks.has(workerId)) {
990
- return;
991
- }
992
- warnedWorkerVersionFallbacks.add(workerId);
993
- console.warn(
994
- `loaders.gl: ${worker.name} loader worker version is "latest" because __VERSION__ was not injected. Fetching ${url} from CDN.`
995
- );
996
- }
220
+ var import_tasks = require("@math.gl/core/tasks");
997
221
 
998
222
  // src/worker-utils/lib/worker-api/process-on-worker.ts
999
- function canProcessOnWorker(worker, options) {
1000
- if (!WorkerFarm.isSupported()) {
1001
- return false;
1002
- }
1003
- const workerOptions = options == null ? void 0 : options[worker.id];
1004
- return Boolean(
1005
- (worker.worker || worker.loadWorker || (workerOptions == null ? void 0 : workerOptions.workerUrl)) && (options == null ? void 0 : options.worker)
1006
- );
1007
- }
1008
- function canProcessOnWorkerInBatches(worker, options = {}) {
1009
- if (!canProcessOnWorker(worker, options)) return false;
1010
- if (options.workerInBatches !== void 0) return options.workerInBatches;
1011
- return Boolean(
1012
- worker.workerInBatches && !options.source && !getConfiguredWorkerURL(worker, options)
1013
- );
1014
- }
1015
- async function processOnWorker(worker, data, options = {}, context = {}, jobContext = {}) {
1016
- var _a;
1017
- throwIfAborted(options.signal);
1018
- const name = getWorkerName(worker);
1019
- const workerFarm = WorkerFarm.getWorkerFarm(options);
1020
- const workerPool = workerFarm.getWorkerPool(getWorkerPoolTarget(worker, options, name));
1021
- const jobName = options.jobName || worker.name;
1022
- const job = await workerPool.startJob(
1023
- jobName,
1024
- // eslint-disable-next-line
1025
- onMessage.bind(null, context, options),
1026
- void 0,
1027
- options.signal
1028
- );
1029
- try {
1030
- if ((_a = options.signal) == null ? void 0 : _a.aborted) job.abort(getAbortReason(options.signal));
1031
- const { signal: _signal, onProgress: _onProgress, ...workerOptions } = options;
1032
- const transferableOptions = getTransferListForWriter(workerOptions);
1033
- const transferableContext = getTransferListForWriter(jobContext);
1034
- if (job.isRunning) {
1035
- job.postMessage("process", {
1036
- input: data,
1037
- options: transferableOptions,
1038
- context: transferableContext
1039
- });
1040
- }
1041
- const result = await job.result;
1042
- return result.result;
1043
- } catch (error) {
1044
- job.abort(error);
1045
- throw error;
1046
- }
1047
- }
1048
- function processOnWorkerInBatches(worker, input, options = {}, context = {}, jobContext = {}) {
1049
- return processOnWorkerInBatchesIterator(worker, input, options, context, jobContext);
1050
- }
1051
- async function* processOnWorkerInBatchesIterator(worker, input, options, context, jobContext) {
1052
- throwIfAborted(options.signal);
1053
- const name = getWorkerName(worker);
1054
- const workerFarm = WorkerFarm.getWorkerFarm(options);
1055
- const workerPool = workerFarm.getWorkerPool(getWorkerPoolTarget(worker, options, name));
1056
- const outputBatches = new AsyncQueue();
1057
- const inputIterator = getAsyncIterator(input);
1058
- let outputFinished = false;
1059
- let inputFinished = false;
1060
- let inputCleanupRequested = false;
1061
- let inputRequest = Promise.resolve();
1062
- const batchJobFailed = new Error("Worker batch job failed");
1063
- const closeJobInput = () => {
1064
- if (!inputFinished && !inputCleanupRequested) {
1065
- inputCleanupRequested = true;
1066
- closeInputIterator(inputIterator);
1067
- }
1068
- };
1069
- const finishOutput = () => {
1070
- if (!outputFinished) {
1071
- outputFinished = true;
1072
- outputBatches.close();
1073
- }
1074
- };
1075
- const failOutput = (_error) => {
1076
- if (!outputFinished) {
1077
- outputFinished = true;
1078
- outputBatches.enqueue(batchJobFailed);
1079
- outputBatches.close();
1080
- }
1081
- };
1082
- const job = await workerPool.startJob(
1083
- options.jobName || worker.name,
1084
- (activeJob, type, payload) => {
1085
- switch (type) {
1086
- case "progress":
1087
- reportProgress(activeJob, options, payload);
1088
- break;
1089
- case "input-request":
1090
- inputRequest = inputRequest.then(async () => {
1091
- if (!activeJob.isRunning) return;
1092
- const nextBatch = await inputIterator.next();
1093
- if (!activeJob.isRunning) {
1094
- return;
1095
- }
1096
- if (nextBatch.done) {
1097
- inputFinished = true;
1098
- activeJob.postMessage("input-done", {});
1099
- } else {
1100
- activeJob.postMessage("input-batch", { input: nextBatch.value });
1101
- }
1102
- }).catch((error) => activeJob.abort(error));
1103
- break;
1104
- case "output-batch":
1105
- outputBatches.push(payload.result);
1106
- break;
1107
- case "done":
1108
- activeJob.done(payload);
1109
- finishOutput();
1110
- break;
1111
- case "error": {
1112
- const error = new Error(payload.error || "Worker batch processing failed");
1113
- activeJob.error(error);
1114
- failOutput(error);
1115
- break;
1116
- }
1117
- case "process":
1118
- void onMessage(context, options, activeJob, type, payload);
1119
- break;
1120
- default: {
1121
- const error = new Error(`Unexpected worker batch message: ${type}`);
1122
- activeJob.error(error);
1123
- failOutput(error);
1124
- break;
1125
- }
1126
- }
1127
- },
1128
- void 0,
1129
- options.signal
1130
- ).catch((error) => {
1131
- closeJobInput();
1132
- throw error;
1133
- });
1134
- void job.result.catch((error) => {
1135
- failOutput(error);
1136
- closeJobInput();
1137
- });
1138
- try {
1139
- const { signal: _signal, onProgress: _onProgress, ...workerOptions } = options;
1140
- if (job.isRunning) {
1141
- job.postMessage("process-in-batches", {
1142
- options: getTransferListForWriter(workerOptions),
1143
- context: getTransferListForWriter(jobContext)
1144
- });
1145
- }
1146
- try {
1147
- for await (const outputBatch of outputBatches) {
1148
- yield outputBatch;
1149
- if (job.isRunning) {
1150
- job.postMessage("output-ack", {});
1151
- }
1152
- }
1153
- } catch (error) {
1154
- if (error === batchJobFailed) {
1155
- await job.result;
1156
- }
1157
- throw error;
1158
- }
1159
- await job.result;
1160
- } finally {
1161
- if (job.isRunning) {
1162
- job.abort(createAbortError2("Worker batch iterator was closed"));
1163
- }
1164
- closeJobInput();
1165
- }
1166
- }
1167
- function throwIfAborted(signal) {
1168
- if (!(signal == null ? void 0 : signal.aborted)) {
1169
- return;
1170
- }
1171
- throw getAbortReason(signal);
1172
- }
1173
- function getAbortReason(signal) {
1174
- return signal ? signal.reason : createAbortError2("Worker job was aborted");
1175
- }
1176
- function createAbortError2(message) {
1177
- const error = new Error(message);
1178
- error.name = "AbortError";
1179
- return error;
1180
- }
1181
- function getAsyncIterator(input) {
1182
- if (Symbol.asyncIterator in input) {
1183
- return input[Symbol.asyncIterator]();
1184
- }
1185
- return (async function* iterateSynchronously() {
1186
- yield* input;
1187
- })();
1188
- }
1189
- function closeInputIterator(inputIterator) {
1190
- var _a;
1191
- try {
1192
- void Promise.resolve((_a = inputIterator.return) == null ? void 0 : _a.call(inputIterator)).catch(() => void 0);
1193
- } catch {
1194
- }
1195
- }
1196
- function getWorkerPoolTarget(worker, options, name) {
1197
- if (options.source) {
1198
- return { name, source: options.source };
1199
- }
1200
- const customWorkerUrl = getCustomWorkerURL(worker, options);
1201
- if (customWorkerUrl) {
1202
- return { name, url: customWorkerUrl };
1203
- }
1204
- if (isBrowser2 && worker.loadWorker) {
1205
- return {
1206
- name,
1207
- loadWorker: worker.loadWorker,
1208
- getUrl: () => getWorkerURL(worker, options),
1209
- urlKey: getDefaultWorkerURL(worker)
1210
- };
1211
- }
1212
- return { name, url: getWorkerURL(worker, options) };
1213
- }
1214
- async function onMessage(context, options, job, type, payload) {
1215
- switch (type) {
1216
- case "progress":
1217
- reportProgress(job, options, payload);
1218
- break;
1219
- case "done":
1220
- job.done(payload);
1221
- break;
1222
- case "error":
1223
- job.error(new Error(payload.error));
1224
- break;
1225
- case "process":
1226
- const { id, input, options: processOptions } = payload;
1227
- try {
1228
- if (!context.process) {
1229
- job.postMessage("error", { id, error: "Worker not set up to process on main thread" });
1230
- return;
1231
- }
1232
- const result = await context.process(
1233
- input,
1234
- { ...processOptions, signal: options.signal, onProgress: options.onProgress },
1235
- void 0,
1236
- payload.context || {}
1237
- );
1238
- job.postMessage("done", { id, result });
1239
- } catch (error) {
1240
- const message = error instanceof Error ? error.message : "unknown error";
1241
- job.postMessage("error", { id, error: message });
1242
- }
1243
- break;
1244
- default:
1245
- console.warn(`process-on-worker: unknown message ${type}`);
1246
- }
1247
- }
1248
- function reportProgress(job, options, payload) {
1249
- var _a;
1250
- if (!job.isRunning || !payload.progress) return;
1251
- try {
1252
- (_a = options.onProgress) == null ? void 0 : _a.call(options, payload.progress);
1253
- } catch (error) {
1254
- job.abort(error);
1255
- }
1256
- }
223
+ var import_tasks2 = require("@math.gl/core/tasks");
1257
224
 
1258
225
  // src/worker-utils/lib/worker-api/validate-worker-version.ts
1259
226
  function validateWorkerVersion(worker, coreVersion = VERSION2) {
@@ -1285,7 +252,7 @@ function canParseWithWorker(loader, options) {
1285
252
  if (loader.id === "csv" && !shouldParseCSVWithWorker(options)) {
1286
253
  return false;
1287
254
  }
1288
- return Boolean(canProcessOnWorker(loader, workerOptions));
255
+ return Boolean((0, import_tasks2.canProcessOnWorker)(loader, workerOptions));
1289
256
  }
1290
257
  function canParseWithWorkerInBatches(loader, options) {
1291
258
  const parquetOptions = options == null ? void 0 : options.parquet;
@@ -1293,7 +260,7 @@ function canParseWithWorkerInBatches(loader, options) {
1293
260
  return false;
1294
261
  }
1295
262
  return Boolean(
1296
- loader.workerInBatches && canParseWithWorker(loader, options) && canProcessOnWorkerInBatches(loader, getWorkerOptions(options))
263
+ loader.workerInBatches && canParseWithWorker(loader, options) && (0, import_tasks2.canProcessOnWorkerInBatches)(loader, getWorkerOptions(options))
1297
264
  );
1298
265
  }
1299
266
  function shouldParseWithWorker(loader, data, options, context, estimateLoader = loader) {
@@ -1316,7 +283,7 @@ function shouldParseWithWorker(loader, data, options, context, estimateLoader =
1316
283
  }
1317
284
  async function parseWithWorker(loader, data, options, context, parseOnMainThread, signal) {
1318
285
  const workerSignal = signal || getWorkerAbortSignal(options) || (context == null ? void 0 : context.signal);
1319
- const result = await processOnWorker(
286
+ const result = await (0, import_tasks2.processOnWorker)(
1320
287
  loader,
1321
288
  data,
1322
289
  {
@@ -1346,7 +313,7 @@ async function parseWithWorker(loader, data, options, context, parseOnMainThread
1346
313
  }
1347
314
  async function* parseWithWorkerInBatches(loader, inputIterator, options, context, parseOnMainThread, signal) {
1348
315
  const workerSignal = signal || getWorkerAbortSignal(options) || (context == null ? void 0 : context.signal);
1349
- const outputIterator = processOnWorkerInBatches(
316
+ const outputIterator = (0, import_tasks2.processOnWorkerInBatches)(
1350
317
  loader,
1351
318
  inputIterator,
1352
319
  {
@@ -1467,7 +434,7 @@ function getSerializableLoaderContext(context) {
1467
434
  loaders,
1468
435
  coreApi: coreApi2,
1469
436
  signal,
1470
- reportProgress: reportProgress2,
437
+ reportProgress,
1471
438
  _parse,
1472
439
  _parseSync,
1473
440
  _parseInBatches,
@@ -1487,7 +454,7 @@ function isLoaderWithWorkerResultDeserializer(loader) {
1487
454
  // src/loader-utils/lib/worker-loader-utils/encode-with-worker.ts
1488
455
  function canEncodeWithWorker(writer, options) {
1489
456
  var _a, _b;
1490
- if (!WorkerFarm.isSupported()) {
457
+ if (!import_tasks.WorkerFarm.isSupported()) {
1491
458
  return false;
1492
459
  }
1493
460
  const nodeWorkers = (options == null ? void 0 : options._nodeWorkers) ?? ((_a = options == null ? void 0 : options.core) == null ? void 0 : _a._nodeWorkers);
@@ -1658,7 +625,7 @@ var STAT_ACTIVE_REQUESTS = "Active Requests";
1658
625
  var STAT_CANCELLED_REQUESTS = "Cancelled Requests";
1659
626
  var STAT_QUEUED_REQUESTS_EVER = "Queued Requests Ever";
1660
627
  var STAT_ACTIVE_REQUESTS_EVER = "Active Requests Ever";
1661
- var DEFAULT_PROPS2 = {
628
+ var DEFAULT_PROPS = {
1662
629
  id: "request-scheduler",
1663
630
  /** Specifies if the request scheduler should throttle incoming requests, mainly for comparative testing. */
1664
631
  throttleRequests: true,
@@ -1680,7 +647,7 @@ var RequestScheduler = class {
1680
647
  /** Pending arrival debounce or next-tick refill; only new arrivals replace this timer. */
1681
648
  updateTimer = null;
1682
649
  constructor(props = {}) {
1683
- this.props = { ...DEFAULT_PROPS2, ...props };
650
+ this.props = { ...DEFAULT_PROPS, ...props };
1684
651
  this.stats = new import_stats.Stats({ id: this.props.id });
1685
652
  this.stats.get(STAT_QUEUED_REQUESTS);
1686
653
  this.stats.get(STAT_ACTIVE_REQUESTS);
@@ -4343,7 +3310,7 @@ async function encode(data, writer, options_) {
4343
3310
  return encodeWithCommandLineTool(writer, data, options);
4344
3311
  }
4345
3312
  if (canEncodeWithWorker(writer, options)) {
4346
- return await processOnWorker(writer, data, options);
3313
+ return await (0, import_tasks2.processOnWorker)(writer, data, options);
4347
3314
  }
4348
3315
  return await writer.encode(data, options);
4349
3316
  }
@@ -4519,7 +3486,7 @@ function makeStream(source, options) {
4519
3486
  }
4520
3487
 
4521
3488
  // dist/null-loader.js
4522
- var VERSION4 = true ? "5.0.0-beta.1" : "latest";
3489
+ var VERSION4 = true ? "5.0.0-beta.2" : "latest";
4523
3490
  var NullWorkerLoader = {
4524
3491
  dataType: null,
4525
3492
  batchType: null,