@danielsimonjr/memoryjs 2.8.0 → 2.8.1

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/index.cjs CHANGED
@@ -3444,6 +3444,10 @@ var init_WorkerTaskManager = __esm({
3444
3444
  touchedPoolIds = /* @__PURE__ */ new Set();
3445
3445
  cancelledTaskIds = /* @__PURE__ */ new Set();
3446
3446
  handleStatus = /* @__PURE__ */ new Map();
3447
+ // Live `pool.exec(...)` promises by task id. Populated when a task starts
3448
+ // running so the handle can call `.cancel()` on the workerpool promise
3449
+ // for mid-execution cancellation. Cleared on completion / failure.
3450
+ liveExecPromises = /* @__PURE__ */ new Map();
3447
3451
  constructor(opts = {}) {
3448
3452
  this.queue = new TaskQueue({
3449
3453
  concurrency: opts.concurrency,
@@ -3483,7 +3487,13 @@ var init_WorkerTaskManager = __esm({
3483
3487
  this.handleStatus.set(id, "running" /* RUNNING */);
3484
3488
  const pool = this.poolManager.getPool(input.workerType, opts.poolConfig);
3485
3489
  this.touchedPoolIds.add(input.workerType);
3486
- return await pool.exec(input.methodName, input.args);
3490
+ const execPromise = pool.exec(input.methodName, input.args);
3491
+ this.liveExecPromises.set(id, execPromise);
3492
+ try {
3493
+ return await execPromise;
3494
+ } finally {
3495
+ this.liveExecPromises.delete(id);
3496
+ }
3487
3497
  }
3488
3498
  };
3489
3499
  const result = this.queue.enqueue(task).then(async (res) => {
@@ -3505,8 +3515,21 @@ var init_WorkerTaskManager = __esm({
3505
3515
  const evicted = this.queue.cancel(id);
3506
3516
  if (evicted) {
3507
3517
  this.handleStatus.set(id, "cancelled" /* CANCELLED */);
3518
+ return true;
3519
+ }
3520
+ const live = this.liveExecPromises.get(id);
3521
+ if (live && typeof live.cancel === "function") {
3522
+ if (live.pending === false) return false;
3523
+ try {
3524
+ live.cancel();
3525
+ this.handleStatus.set(id, "cancelled" /* CANCELLED */);
3526
+ return true;
3527
+ } catch (e) {
3528
+ logger.warn(`[WorkerTaskManager] cancel() on live exec for ${id} threw:`, e);
3529
+ return false;
3530
+ }
3508
3531
  }
3509
- return evicted;
3532
+ return false;
3510
3533
  },
3511
3534
  status: () => this.handleStatus.get(id) ?? "pending" /* PENDING */
3512
3535
  };