@zwave-js/waddle 1.2.3 → 1.3.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/README.md CHANGED
@@ -125,6 +125,19 @@ const task = scheduler.findTask((task) => task.tag?.id === "rebuild-routes");
125
125
  // ^ Either a Promise or undefined, depending on whether the task exists or not
126
126
  ```
127
127
 
128
+ This also finds parent tasks that are waiting for a subtask.
129
+
130
+ The task function receives its own task as the `thisTask` argument. The task can use it to identify itself when removing tasks (see below):
131
+
132
+ ```js
133
+ scheduler.queueTask({
134
+ priority: TaskPriority.Normal,
135
+ task: async function* (thisTask) {
136
+ yield () => scheduler.removeTasks((task) => task !== thisTask);
137
+ },
138
+ });
139
+ ```
140
+
128
141
  #### Task Priority
129
142
 
130
143
  There are several task priorities defined:
@@ -430,6 +443,8 @@ const parentTask = scheduler.queueTask({
430
443
 
431
444
  To cancel one or more tasks, simply call the `scheduler.removeTasks` method. This method takes a predicate function that will be called for each active and queued task. If the predicate returns `true`, the task will be removed from the scheduler. This can be used to cancel tasks that are no longer needed.
432
445
 
446
+ The predicate is also called for parent tasks that are waiting for a subtask. Canceling such a parent also cancels the subtasks it is waiting for. Canceling only a subtask rejects the promise the parent is waiting for, so the parent can handle the error and continue.
447
+
433
448
  Note that running tasks will not be canceled immediately. Instead they will run until the next `yield` point first.
434
449
 
435
450
  ```js
@@ -457,6 +472,8 @@ if (canceled) {
457
472
  }
458
473
  ```
459
474
 
475
+ When removing tasks, the `thisTask` argument can be used to avoid removing the currently running task.
476
+
460
477
  Canceled tasks will result in an `Error`. Take care of this when awaiting them!
461
478
 
462
479
  By default, each canceled tasks will be rejected with this error:
@@ -481,6 +498,16 @@ const scheduler = new TaskScheduler(() => new Error("We are all doomed!"));
481
498
  ```
482
499
 
483
500
  ## Changelog
501
+ ### 1.3.1 (2026-10-06)
502
+
503
+ - Fixed: `removeTasks` and `findTasks` now also consider parent tasks that are waiting for a subtask
504
+ - Fixed: Tasks with the `Restart` interrupt behavior were restarted every time they yielded a subtask, so they never finished
505
+ - Fixed: A task that was restarted while waiting for a yielded promise could receive that promise's result or error after it was restarted
506
+
507
+ ### 1.3.0 (2026-09-29)
508
+
509
+ - The task function now receives a handle to its own task as the first argument. It can be used to identify the task in `removeTasks` predicates.
510
+
484
511
  ### 1.2.3 (2026-07-30)
485
512
 
486
513
  - The scheduler now starts its run loop with a timer instead of `setImmediate`, so it no longer requires a Node.js-compatible runtime or polyfills
@@ -1,14 +1,13 @@
1
- /** A high-level task that can be started and stepped through */
2
- export interface Task<TReturn, TaskTag extends {
1
+ /** The read-only view of a task that gets passed to its own task function */
2
+ export interface TaskHandle<TaskTag extends {
3
3
  id: string;
4
4
  } = {
5
5
  id: string;
6
- }, TError extends Error = Error> {
6
+ }> {
7
7
  readonly id: number;
8
8
  readonly timestamp: number;
9
- readonly builder: TaskBuilder<TReturn, TaskTag>;
10
9
  /** The parent task spawning this subtask, if any */
11
- readonly parent?: Task<unknown, TaskTag, TError>;
10
+ readonly parent?: TaskHandle<TaskTag>;
12
11
  /** A name to identify the task */
13
12
  readonly name?: string;
14
13
  /** A tag to identify the task programmatically */
@@ -19,6 +18,18 @@ export interface Task<TReturn, TaskTag extends {
19
18
  readonly group?: TaskConcurrencyGroup;
20
19
  /** How the task should behave when interrupted */
21
20
  readonly interrupt: TaskInterruptBehavior;
21
+ /** The current state of the task */
22
+ get state(): TaskState;
23
+ }
24
+ /** A high-level task that can be started and stepped through */
25
+ export interface Task<TReturn, TaskTag extends {
26
+ id: string;
27
+ } = {
28
+ id: string;
29
+ }, TError extends Error = Error> extends TaskHandle<TaskTag> {
30
+ readonly builder: TaskBuilder<TReturn, TaskTag>;
31
+ /** The parent task spawning this subtask, if any */
32
+ readonly parent?: Task<unknown, TaskTag, TError>;
22
33
  /** Starts the task it if hasn't been started yet, and executes the next step of the task */
23
34
  step(): Promise<TaskStepResult<TReturn, TaskTag>>;
24
35
  /** Stops the task without further executing it, cleans up, and prepares it for starting again */
@@ -27,8 +38,6 @@ export interface Task<TReturn, TaskTag extends {
27
38
  resolve(result: TReturn): void;
28
39
  /** Rejects the task's promise to notify the caller */
29
40
  reject(error: TError): void;
30
- /** The current state of the task */
31
- get state(): TaskState;
32
41
  readonly generator: ReturnType<TaskBuilder<TReturn>["task"]> | undefined;
33
42
  readonly promise: Promise<TReturn>;
34
43
  }
@@ -57,8 +66,11 @@ export interface TaskBuilder<TReturn, TaskTag extends {
57
66
  * - Or another task, in which case it must yield a TaskBuilder object or a function that returns one
58
67
  *
59
68
  * Yielded Promises should not spawn new tasks. If they do, the spawned tasks MUST have a higher priority than the parent task.
69
+ *
70
+ * @param thisTask The task that runs this function. It is the same object the scheduler passes to `removeTasks` predicates,
71
+ * so it can be compared by identity. It stays the same when the task gets restarted.
60
72
  */
61
- task: () => AsyncGenerator<(() => Promise<unknown> | TaskBuilder<unknown, TaskTag, unknown>) | (() => TaskBuilder<unknown, TaskTag, unknown>) | TaskBuilder<unknown, TaskTag, unknown> | undefined, TReturn, TInner>;
73
+ task: (thisTask: TaskHandle) => AsyncGenerator<(() => Promise<unknown> | TaskBuilder<unknown, TaskTag, unknown>) | (() => TaskBuilder<unknown, TaskTag, unknown>) | TaskBuilder<unknown, TaskTag, unknown> | undefined, TReturn, TInner>;
62
74
  /** A cleanup function that gets called when the task is dropped */
63
75
  cleanup?: () => Promise<void>;
64
76
  }
@@ -136,10 +148,29 @@ export declare class TaskScheduler<TaskTag extends {
136
148
  private _stopSignal;
137
149
  private _stopPromise;
138
150
  queueTask<T>(builder: TaskBuilder<T, TaskTag>): Promise<T>;
139
- /** Removes/stops tasks matching the given predicate. Returns `true` when a task was removed, `false` otherwise. */
151
+ /**
152
+ * Removes/stops tasks matching the given predicate. Returns `true` when a task was removed, `false` otherwise.
153
+ *
154
+ * The predicate also sees parent tasks that are waiting for a subtask.
155
+ * Removing such a parent also removes the subtasks it is waiting for.
156
+ */
140
157
  removeTasks(predicate: (task: Task<unknown, TaskTag>) => boolean, reason?: TError): Promise<boolean>;
141
- /** Removes a single task from the queue, resets it and rejects its promise */
142
- private dropTask;
158
+ /** Returns the queued or current task that is `task` itself or one of its subtasks, if any */
159
+ private findLeafTask;
160
+ /**
161
+ * Removes `leaf` from the queue, then resets and rejects it and each of its parents up to and including `outermost`.
162
+ * The parent of `outermost` is put back into the queue first.
163
+ */
164
+ private dropTasks;
165
+ /**
166
+ * Puts a parent back into the queue when its subtask is finished or removed.
167
+ * Call this before cleaning up the subtask, so the parent can be found during the cleanup.
168
+ */
169
+ private restoreParentTask;
170
+ /**
171
+ * Returns the promise of the first task matching the given predicate, if any.
172
+ * The predicate also sees parent tasks that are waiting for a subtask.
173
+ */
143
174
  findTask<T = unknown>(predicate: (task: Task<T, TaskTag>) => boolean): Promise<T> | undefined;
144
175
  /** Creates a task that can be executed */
145
176
  private createTask;
package/build/cjs/Task.js CHANGED
@@ -33,6 +33,12 @@ function getTaskName(task) {
33
33
  return `${task.name ?? (task.tag && JSON.stringify(task.tag)) ?? "unnamed"} (ID ${task.id})`;
34
34
  }
35
35
  __name(getTaskName, "getTaskName");
36
+ function* selfAndParents(task) {
37
+ for (let t = task; t; t = t.parent) {
38
+ yield t;
39
+ }
40
+ }
41
+ __name(selfAndParents, "selfAndParents");
36
42
  function isTaskBuilder(obj) {
37
43
  return typeof obj === "object" && typeof obj.task === "function" && typeof obj.priority === "number";
38
44
  }
@@ -114,53 +120,98 @@ class TaskScheduler {
114
120
  this._continueSignal.resolve();
115
121
  return task.promise;
116
122
  }
117
- /** Removes/stops tasks matching the given predicate. Returns `true` when a task was removed, `false` otherwise. */
123
+ /**
124
+ * Removes/stops tasks matching the given predicate. Returns `true` when a task was removed, `false` otherwise.
125
+ *
126
+ * The predicate also sees parent tasks that are waiting for a subtask.
127
+ * Removing such a parent also removes the subtasks it is waiting for.
128
+ */
118
129
  async removeTasks(predicate, reason) {
119
- const tasksToRemove = [];
120
- let currentTaskToRemove;
121
- for (const task of this._tasks) {
122
- if (predicate(task)) {
123
- if (task === this._currentTask) {
124
- currentTaskToRemove = task;
130
+ const tasksToRemove = /* @__PURE__ */ new Set();
131
+ const currentTasksToRemove = [];
132
+ for (const queued of this._tasks) {
133
+ for (const task of selfAndParents(queued)) {
134
+ if (!predicate(task))
135
+ continue;
136
+ if (queued === this._currentTask) {
137
+ currentTasksToRemove.push(task);
125
138
  } else {
126
- tasksToRemove.push(task);
139
+ tasksToRemove.add(task);
127
140
  }
128
141
  }
129
142
  }
130
- if (currentTaskToRemove) {
131
- tasksToRemove.push(currentTaskToRemove);
143
+ for (const task of currentTasksToRemove) {
144
+ tasksToRemove.add(task);
132
145
  }
133
146
  reason ??= this.defaultErrorFactory();
134
147
  for (const task of tasksToRemove) {
135
- if (this._currentTask !== task && !this._tasks.contains(task)) {
148
+ const leaf = this.findLeafTask(task);
149
+ if (!leaf)
136
150
  continue;
151
+ let outermost = task;
152
+ for (let t = task.parent; t; t = t.parent) {
153
+ if (tasksToRemove.has(t))
154
+ outermost = t;
137
155
  }
138
- await this.dropTask(task, reason);
156
+ await this.dropTasks(leaf, outermost, reason);
139
157
  }
140
158
  if (this._continueSignal)
141
159
  this._continueSignal.resolve();
142
- return tasksToRemove.length > 0;
160
+ return tasksToRemove.size > 0;
143
161
  }
144
- /** Removes a single task from the queue, resets it and rejects its promise */
145
- async dropTask(task, reason) {
146
- if (this.verbose) {
147
- console.log(`Removing task: ${getTaskName(task)}`);
162
+ /** Returns the queued or current task that is `task` itself or one of its subtasks, if any */
163
+ findLeafTask(task) {
164
+ const leaves = this._currentTask ? [this._currentTask, ...this._tasks] : this._tasks;
165
+ for (const leaf of leaves) {
166
+ for (const t of selfAndParents(leaf)) {
167
+ if (t === task)
168
+ return leaf;
169
+ }
148
170
  }
149
- this._tasks.remove(task);
150
- if (this._currentTask === task) {
171
+ }
172
+ /**
173
+ * Removes `leaf` from the queue, then resets and rejects it and each of its parents up to and including `outermost`.
174
+ * The parent of `outermost` is put back into the queue first.
175
+ */
176
+ async dropTasks(leaf, outermost, reason) {
177
+ this._tasks.remove(leaf);
178
+ if (this._currentTask === leaf) {
151
179
  this._currentTask = void 0;
152
180
  }
153
- await task.reset().catch(import_utils.noop);
154
- task.reject(reason);
155
- if (task.parent) {
181
+ if (outermost.parent)
182
+ this.restoreParentTask(outermost.parent);
183
+ for (let task = leaf; ; task = task.parent) {
156
184
  if (this.verbose) {
157
- console.log(`Restoring parent task: ${getTaskName(task.parent)}`);
185
+ console.log(`Removing task: ${getTaskName(task)}`);
158
186
  }
159
- this._tasks.add(task.parent);
187
+ await task.reset().catch(import_utils.noop);
188
+ task.reject(reason);
189
+ if (task === outermost)
190
+ break;
160
191
  }
161
192
  }
193
+ /**
194
+ * Puts a parent back into the queue when its subtask is finished or removed.
195
+ * Call this before cleaning up the subtask, so the parent can be found during the cleanup.
196
+ */
197
+ restoreParentTask(parent) {
198
+ if (this.verbose) {
199
+ console.log(`Restoring parent task: ${getTaskName(parent)}`);
200
+ }
201
+ this._tasks.add(parent);
202
+ }
203
+ /**
204
+ * Returns the promise of the first task matching the given predicate, if any.
205
+ * The predicate also sees parent tasks that are waiting for a subtask.
206
+ */
162
207
  findTask(predicate) {
163
- return this._tasks.find((t) => predicate(t))?.promise;
208
+ for (const queued of this._tasks) {
209
+ for (const task of selfAndParents(queued)) {
210
+ if (predicate(task)) {
211
+ return task.promise;
212
+ }
213
+ }
214
+ }
164
215
  }
165
216
  /** Creates a task that can be executed */
166
217
  createTask(builder, parent) {
@@ -171,7 +222,7 @@ class TaskScheduler {
171
222
  let prevResult;
172
223
  let waitError;
173
224
  const self = this;
174
- return {
225
+ const task = {
175
226
  id: this._idGenerator(),
176
227
  timestamp: (0, import_utils.highResTimestamp)(),
177
228
  builder,
@@ -189,9 +240,15 @@ class TaskScheduler {
189
240
  promise: waitForPromise
190
241
  };
191
242
  } else if (state === TaskState.AwaitingTask) {
243
+ if (waitForPromise) {
244
+ return {
245
+ newState: TaskState.AwaitingPromise,
246
+ promise: waitForPromise
247
+ };
248
+ }
192
249
  throw new Error("Cannot step through a task that is waiting for another task");
193
250
  }
194
- generator ??= builder.task();
251
+ generator ??= builder.task(task);
195
252
  state = TaskState.Active;
196
253
  const gen = generator;
197
254
  let genResult;
@@ -218,10 +275,14 @@ class TaskScheduler {
218
275
  if (waitFor instanceof Promise) {
219
276
  state = TaskState.AwaitingPromise;
220
277
  waitForPromise = waitFor.then((result) => {
221
- prevResult = result;
278
+ if (generator === gen)
279
+ prevResult = result;
222
280
  }).catch((e) => {
223
- waitError = e;
281
+ if (generator === gen)
282
+ waitError = e;
224
283
  }).finally(() => {
284
+ if (generator !== gen)
285
+ return;
225
286
  waitForPromise = void 0;
226
287
  if (state === TaskState.AwaitingPromise) {
227
288
  state = TaskState.Active;
@@ -237,11 +298,16 @@ class TaskScheduler {
237
298
  }
238
299
  state = TaskState.AwaitingTask;
239
300
  const subTask = self.createTask(waitFor, this);
240
- subTask.promise.then((result) => {
241
- prevResult = result;
301
+ waitForPromise = subTask.promise.then((result) => {
302
+ if (generator === gen)
303
+ prevResult = result;
242
304
  }).catch((e) => {
243
- waitError = e;
305
+ if (generator === gen)
306
+ waitError = e;
244
307
  }).finally(() => {
308
+ if (generator !== gen)
309
+ return;
310
+ waitForPromise = void 0;
245
311
  if (state === TaskState.AwaitingTask) {
246
312
  state = TaskState.Active;
247
313
  }
@@ -280,6 +346,7 @@ class TaskScheduler {
280
346
  return generator;
281
347
  }
282
348
  };
349
+ return task;
283
350
  }
284
351
  start() {
285
352
  this._stopSignal = (0, import_deferred_promise.createDeferredPromise)();
@@ -315,13 +382,9 @@ class TaskScheduler {
315
382
  const finalizeCurrentTask = /* @__PURE__ */ __name(async () => {
316
383
  this._tasks.remove(task);
317
384
  this._currentTask = void 0;
385
+ if (task.parent)
386
+ this.restoreParentTask(task.parent);
318
387
  await task.reset();
319
- if (task.parent) {
320
- if (this.verbose) {
321
- console.log(`Restoring parent task: ${getTaskName(task.parent)}`);
322
- }
323
- this._tasks.add(task.parent);
324
- }
325
388
  }, "finalizeCurrentTask");
326
389
  waitFor = void 0;
327
390
  let stepResult;
@@ -367,6 +430,7 @@ class TaskScheduler {
367
430
  }
368
431
  this._tasks.add(stepResult.task);
369
432
  this._tasks.remove(task);
433
+ this._currentTask = void 0;
370
434
  continue;
371
435
  } else {
372
436
  continue;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/Task.ts"],
4
- "sourcesContent": ["import type { CompareResult } from \"alcalzone-shared/comparable\";\nimport {\n\ttype DeferredPromise,\n\tcreateDeferredPromise,\n} from \"alcalzone-shared/deferred-promise\";\nimport { SortedList } from \"alcalzone-shared/sorted-list\";\nimport { createWrappingCounter } from \"./wrappingCounter.js\";\nimport { evalOrStatic, highResTimestamp, noop } from \"./utils.js\";\n\n/** A high-level task that can be started and stepped through */\nexport interface Task<\n\tTReturn,\n\tTaskTag extends { id: string } = { id: string },\n\tTError extends Error = Error,\n> {\n\treadonly id: number;\n\treadonly timestamp: number;\n\treadonly builder: TaskBuilder<TReturn, TaskTag>;\n\n\t/** The parent task spawning this subtask, if any */\n\treadonly parent?: Task<unknown, TaskTag, TError>;\n\n\t/** A name to identify the task */\n\treadonly name?: string;\n\t/** A tag to identify the task programmatically */\n\treadonly tag?: TaskTag;\n\t/** The task's priority */\n\treadonly priority: TaskPriority;\n\t/** The concurrency group this task belongs to */\n\treadonly group?: TaskConcurrencyGroup;\n\t/** How the task should behave when interrupted */\n\treadonly interrupt: TaskInterruptBehavior;\n\t/** Starts the task it if hasn't been started yet, and executes the next step of the task */\n\tstep(): Promise<TaskStepResult<TReturn, TaskTag>>;\n\t/** Stops the task without further executing it, cleans up, and prepares it for starting again */\n\treset(): Promise<void>;\n\t/** Resolves the task's promise to notify the caller */\n\tresolve(result: TReturn): void;\n\t/** Rejects the task's promise to notify the caller */\n\treject(error: TError): void;\n\t/** The current state of the task */\n\tget state(): TaskState;\n\n\treadonly generator: ReturnType<TaskBuilder<TReturn>[\"task\"]> | undefined;\n\treadonly promise: Promise<TReturn>;\n}\n\nfunction getTaskName(task: Task<unknown>): string {\n\treturn `${\n\t\ttask.name ?? (task.tag && JSON.stringify(task.tag)) ?? \"unnamed\"\n\t} (ID ${task.id})`;\n}\n\n/** Defines the necessary information for creating a task */\nexport interface TaskBuilder<\n\tTReturn,\n\tTaskTag extends { id: string } = { id: string },\n\tTInner = unknown,\n> {\n\t/** A name to identify the task */\n\tname?: string;\n\t/** A tag to identify the task programmatically */\n\ttag?: TaskTag;\n\t/** The task's priority */\n\tpriority: TaskPriority;\n\t/** How the task should behave when interrupted */\n\tinterrupt?: TaskInterruptBehavior;\n\t/** The concurrency group this task belongs to */\n\tgroup?: TaskConcurrencyGroup;\n\t/**\n\t * The task's main generator function. This is called repeatedly until it's done.\n\t * The function must yield at points where it may be interrupted.\n\t *\n\t * At those points, the task can also wait for something to happen:\n\t * - Either a Promise, in which case it must yield a function that returns that Promise\n\t * - Or another task, in which case it must yield a TaskBuilder object or a function that returns one\n\t *\n\t * Yielded Promises should not spawn new tasks. If they do, the spawned tasks MUST have a higher priority than the parent task.\n\t */\n\ttask: () => AsyncGenerator<\n\t\t| (() => Promise<unknown> | TaskBuilder<unknown, TaskTag, unknown>)\n\t\t| (() => TaskBuilder<unknown, TaskTag, unknown>)\n\t\t| TaskBuilder<unknown, TaskTag, unknown>\n\t\t| undefined,\n\t\tTReturn,\n\t\tTInner\n\t>;\n\t/** A cleanup function that gets called when the task is dropped */\n\tcleanup?: () => Promise<void>;\n}\n\nexport type TaskReturnType<T extends TaskBuilder<unknown>> =\n\tT extends TaskBuilder<infer R> ? R : never;\n\nfunction isTaskBuilder<T>(obj: any): obj is TaskBuilder<T> {\n\treturn (\n\t\ttypeof obj === \"object\" &&\n\t\ttypeof obj.task === \"function\" &&\n\t\ttypeof obj.priority === \"number\"\n\t);\n}\n\n/**\n * The priority of a task.\n *\n * Higher priority tasks are executed first and interrupt lower priority tasks.\n * The recommended priority for application-initiated communication is `Normal`.\n * `Low` and `Lower` are recommended for internal long-running tasks that should not interfere with user-initiated tasks.\n * `Idle` is recommended for tasks that should only run when no other tasks are pending.\n */\nexport enum TaskPriority {\n\tHighest,\n\tHigh = 1,\n\tNormal = 2,\n\tLow = 3,\n\tLower = 4,\n\tIdle = 5,\n}\n\nexport enum TaskState {\n\t/** The task has not been created yet */\n\tNone,\n\t/** The task is being executed */\n\tActive,\n\t/** The task is waiting for a Promise to resolve */\n\tAwaitingPromise,\n\t/** The task is waiting for another task to finish */\n\tAwaitingTask,\n\t/** The task is finished */\n\tDone,\n}\n\nexport enum TaskInterruptBehavior {\n\t/** The task may not be interrupted */\n\tForbidden,\n\t/** The task will be resumed after being interrupted (default) */\n\tResume,\n\t/** The task needs to be restarted after being interrupted */\n\tRestart,\n}\n\nexport type TaskStepResult<\n\tT,\n\tTaskTag extends { id: string } = { id: string },\n> =\n\t| {\n\t\t\tnewState: TaskState.Done;\n\t\t\tresult: T;\n\t }\n\t| {\n\t\t\tnewState: TaskState.Active;\n\t }\n\t| {\n\t\t\t// The task was reset while the step was in flight. The result is stale and must be dropped.\n\t\t\tnewState: TaskState.None;\n\t }\n\t| {\n\t\t\tnewState: TaskState.AwaitingPromise;\n\t\t\tpromise: Promise<unknown>;\n\t }\n\t| {\n\t\t\tnewState: TaskState.AwaitingTask;\n\t\t\ttask: Task<unknown, TaskTag>;\n\t };\n\n/** Identifies a concurrency group. Tasks within the same group cannot run concurrently. */\nexport interface TaskConcurrencyGroup {\n\tid: string;\n}\n\nfunction compareTasks<T1, T2>(a: Task<T1>, b: Task<T2>): CompareResult {\n\t// In the same concurrency group, only one task may be active at a time.\n\tconst aConcurrencyGroup = a.group?.id;\n\tconst bConcurrencyGroup = b.group?.id;\n\tif (\n\t\taConcurrencyGroup &&\n\t\tbConcurrencyGroup &&\n\t\taConcurrencyGroup === bConcurrencyGroup\n\t) {\n\t\tconst aActiveOrWaiting =\n\t\t\ta.state === TaskState.Active ||\n\t\t\ta.state === TaskState.AwaitingPromise ||\n\t\t\ta.state === TaskState.AwaitingTask;\n\t\tconst bActiveOrWaiting =\n\t\t\tb.state === TaskState.Active ||\n\t\t\tb.state === TaskState.AwaitingPromise ||\n\t\t\tb.state === TaskState.AwaitingTask;\n\n\t\tif (aActiveOrWaiting && !bActiveOrWaiting) return 1; // A is already active\n\t\tif (!aActiveOrWaiting && bActiveOrWaiting) return -1; // B is already active\n\n\t\t// None of the tasks is active, fall back to default sorting\n\t}\n\n\t// Sort by priority for tasks not in the same concurrency group\n\tif (a.priority < b.priority) return 1;\n\tif (a.priority > b.priority) return -1;\n\n\t// Deprioritize waiting tasks\n\tconst aWaiting =\n\t\ta.state === TaskState.AwaitingPromise ||\n\t\ta.state === TaskState.AwaitingTask;\n\tconst bWaiting =\n\t\tb.state === TaskState.AwaitingPromise ||\n\t\tb.state === TaskState.AwaitingTask;\n\tif (!aWaiting && bWaiting) return 1;\n\tif (aWaiting && !bWaiting) return -1;\n\n\t// Sort equal priority by timestamp. Newer tasks go to the end of the list\n\tif (a.timestamp < b.timestamp) return 1;\n\tif (a.timestamp > b.timestamp) return -1;\n\n\t// If all else fails, sort by ID\n\treturn Math.sign(b.id - a.id) as CompareResult;\n}\n\nexport class TaskScheduler<\n\tTaskTag extends { id: string } = { id: string },\n\tTError extends Error = Error,\n> {\n\tpublic constructor(\n\t\tprivate defaultErrorFactory: () => TError = () =>\n\t\t\tnew Error(\"Task was removed\") as any,\n\t\tprivate verbose: boolean = false,\n\t) {}\n\n\tprivate _tasks = new SortedList<Task<unknown, TaskTag>>(\n\t\tundefined,\n\t\tcompareTasks,\n\t);\n\tprivate _currentTask: Task<unknown, TaskTag> | undefined;\n\n\tprivate _idGenerator = createWrappingCounter(0xff_ff_ff);\n\tprivate _continueSignal: DeferredPromise<void> | undefined;\n\tprivate _stopSignal: DeferredPromise<void> | undefined;\n\tprivate _stopPromise: DeferredPromise<void> | undefined;\n\n\tpublic queueTask<T>(builder: TaskBuilder<T, TaskTag>): Promise<T> {\n\t\tconst task = this.createTask(builder);\n\t\tthis._tasks.add(task);\n\t\tif (this.verbose) {\n\t\t\tconsole.log(`Task queued: ${getTaskName(task)}`);\n\t\t}\n\n\t\tif (this._continueSignal) this._continueSignal.resolve();\n\t\treturn task.promise;\n\t}\n\n\t/** Removes/stops tasks matching the given predicate. Returns `true` when a task was removed, `false` otherwise. */\n\tpublic async removeTasks(\n\t\tpredicate: (task: Task<unknown, TaskTag>) => boolean,\n\t\treason?: TError,\n\t): Promise<boolean> {\n\t\t// Collect tasks that should be removed, so that we handle the current task last\n\t\tconst tasksToRemove: Task<unknown, TaskTag>[] = [];\n\t\tlet currentTaskToRemove: Task<unknown, TaskTag> | undefined;\n\t\tfor (const task of this._tasks) {\n\t\t\tif (predicate(task)) {\n\t\t\t\tif (task === this._currentTask) {\n\t\t\t\t\tcurrentTaskToRemove = task;\n\t\t\t\t} else {\n\t\t\t\t\ttasksToRemove.push(task);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (currentTaskToRemove) {\n\t\t\ttasksToRemove.push(currentTaskToRemove);\n\t\t}\n\n\t\treason ??= this.defaultErrorFactory();\n\n\t\tfor (const task of tasksToRemove) {\n\t\t\t// Skip tasks the run loop finalized during a previous iteration's await\n\t\t\tif (this._currentTask !== task && !this._tasks.contains(task)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tawait this.dropTask(task, reason);\n\t\t}\n\n\t\tif (this._continueSignal) this._continueSignal.resolve();\n\n\t\treturn tasksToRemove.length > 0;\n\t}\n\n\t/** Removes a single task from the queue, resets it and rejects its promise */\n\tprivate async dropTask(\n\t\ttask: Task<unknown, TaskTag>,\n\t\treason: TError,\n\t): Promise<void> {\n\t\tif (this.verbose) {\n\t\t\tconsole.log(`Removing task: ${getTaskName(task)}`);\n\t\t}\n\t\tthis._tasks.remove(task);\n\t\t// Claim the task before awaiting anything, so the run loop drops the\n\t\t// result of an in-flight step instead of finalizing the task a second time\n\t\tif (this._currentTask === task) {\n\t\t\tthis._currentTask = undefined;\n\t\t}\n\t\tawait task.reset().catch(noop);\n\t\ttask.reject(reason);\n\t\t// Re-add the parent task to the list if there is one\n\t\tif (task.parent) {\n\t\t\tif (this.verbose) {\n\t\t\t\tconsole.log(\n\t\t\t\t\t`Restoring parent task: ${getTaskName(task.parent)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis._tasks.add(task.parent);\n\t\t}\n\t}\n\n\tpublic findTask<T = unknown>(\n\t\tpredicate: (task: Task<T, TaskTag>) => boolean,\n\t): Promise<T> | undefined {\n\t\treturn this._tasks.find((t: any) => predicate(t))?.promise as\n\t\t\t| Promise<T>\n\t\t\t| undefined;\n\t}\n\n\t/** Creates a task that can be executed */\n\tprivate createTask<T>(\n\t\tbuilder: TaskBuilder<T, TaskTag>,\n\t\tparent?: Task<unknown, TaskTag>,\n\t): Task<T, TaskTag, TError> {\n\t\tlet state = TaskState.None;\n\t\tlet generator: ReturnType<TaskBuilder<T, TaskTag>[\"task\"]> | undefined;\n\t\tlet waitForPromise: Promise<unknown> | undefined;\n\t\tconst promise = createDeferredPromise<T>();\n\n\t\tlet prevResult: unknown;\n\t\tlet waitError: unknown;\n\n\t\tconst self = this;\n\n\t\treturn {\n\t\t\tid: this._idGenerator(),\n\t\t\ttimestamp: highResTimestamp(),\n\t\t\tbuilder,\n\t\t\tparent,\n\t\t\tname: builder.name,\n\t\t\ttag: builder.tag,\n\t\t\tpriority: builder.priority,\n\t\t\tgroup: builder.group,\n\t\t\tinterrupt: builder.interrupt ?? TaskInterruptBehavior.Resume,\n\t\t\tpromise,\n\t\t\tasync step() {\n\t\t\t\t// Do not proceed while still waiting for a Promise to resolve\n\t\t\t\tif (state === TaskState.AwaitingPromise && waitForPromise) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tnewState: state,\n\t\t\t\t\t\tpromise: waitForPromise,\n\t\t\t\t\t};\n\t\t\t\t} else if (state === TaskState.AwaitingTask) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\"Cannot step through a task that is waiting for another task\",\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tgenerator ??= builder.task();\n\t\t\t\tstate = TaskState.Active;\n\n\t\t\t\t// Capture the generator so a concurrent reset() can be detected after the await\n\t\t\t\tconst gen = generator;\n\t\t\t\tlet genResult: Awaited<ReturnType<typeof gen.next>>;\n\t\t\t\ttry {\n\t\t\t\t\tgenResult = waitError\n\t\t\t\t\t\t? await gen.throw(waitError)\n\t\t\t\t\t\t: await gen.next(prevResult);\n\t\t\t\t} catch (e) {\n\t\t\t\t\t// Drop errors from a step whose task was reset in the meantime\n\t\t\t\t\tif (generator !== gen) return { newState: TaskState.None };\n\t\t\t\t\tthrow e;\n\t\t\t\t}\n\t\t\t\t// Drop the step result if the task was reset while the generator was running,\n\t\t\t\t// so the task state is not corrupted after the reset\n\t\t\t\tif (generator !== gen) return { newState: TaskState.None };\n\n\t\t\t\tconst { value, done } = genResult;\n\t\t\t\tprevResult = undefined;\n\t\t\t\twaitError = undefined;\n\t\t\t\tif (done) {\n\t\t\t\t\tstate = TaskState.Done;\n\t\t\t\t\treturn {\n\t\t\t\t\t\tnewState: state,\n\t\t\t\t\t\tresult: value,\n\t\t\t\t\t};\n\t\t\t\t} else if (value != undefined) {\n\t\t\t\t\tconst waitFor = evalOrStatic(value);\n\t\t\t\t\tif (waitFor instanceof Promise) {\n\t\t\t\t\t\tstate = TaskState.AwaitingPromise;\n\t\t\t\t\t\twaitForPromise = waitFor\n\t\t\t\t\t\t\t.then((result) => {\n\t\t\t\t\t\t\t\tprevResult = result;\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t.catch((e) => {\n\t\t\t\t\t\t\t\twaitError = e;\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t.finally(() => {\n\t\t\t\t\t\t\t\twaitForPromise = undefined;\n\t\t\t\t\t\t\t\tif (state === TaskState.AwaitingPromise) {\n\t\t\t\t\t\t\t\t\tstate = TaskState.Active;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tnewState: state,\n\t\t\t\t\t\t\tpromise: waitForPromise,\n\t\t\t\t\t\t};\n\t\t\t\t\t} else if (isTaskBuilder(waitFor)) {\n\t\t\t\t\t\tif (waitFor.priority > builder.priority) {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t\"Tasks cannot yield to tasks with lower priority than their own\",\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Create a sub-task with a reference to this task\n\t\t\t\t\t\tstate = TaskState.AwaitingTask;\n\t\t\t\t\t\tconst subTask = self.createTask(waitFor, this);\n\n\t\t\t\t\t\tsubTask.promise\n\t\t\t\t\t\t\t.then((result) => {\n\t\t\t\t\t\t\t\tprevResult = result;\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t.catch((e) => {\n\t\t\t\t\t\t\t\twaitError = e;\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t.finally(() => {\n\t\t\t\t\t\t\t\tif (state === TaskState.AwaitingTask) {\n\t\t\t\t\t\t\t\t\tstate = TaskState.Active;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tnewState: state,\n\t\t\t\t\t\t\ttask: subTask,\n\t\t\t\t\t\t};\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new Error(\"Invalid value yielded by task\");\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn { newState: state };\n\t\t\t\t}\n\t\t\t},\n\t\t\tasync reset() {\n\t\t\t\tif (state === TaskState.None) return;\n\t\t\t\tstate = TaskState.None;\n\t\t\t\twaitForPromise = undefined;\n\t\t\t\tgenerator = undefined;\n\t\t\t\tprevResult = undefined;\n\t\t\t\twaitError = undefined;\n\n\t\t\t\tawait builder.cleanup?.();\n\t\t\t},\n\t\t\tresolve(result) {\n\t\t\t\tpromise.resolve(result);\n\t\t\t},\n\t\t\treject(error) {\n\t\t\t\tpromise.reject(error);\n\t\t\t},\n\t\t\tget state() {\n\t\t\t\treturn state;\n\t\t\t},\n\t\t\tget generator() {\n\t\t\t\treturn generator;\n\t\t\t},\n\t\t};\n\t}\n\n\tpublic start(): void {\n\t\tthis._stopSignal = createDeferredPromise();\n\t\t// A timer instead of setImmediate, which only exists on Node.js and its clones\n\t\tsetTimeout(async () => {\n\t\t\ttry {\n\t\t\t\tawait this.run();\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error(\"Task runner crashed\", e);\n\t\t\t}\n\t\t}, 0);\n\t}\n\n\tprivate async run(): Promise<void> {\n\t\twhile (true) {\n\t\t\tlet waitFor: Promise<unknown> | undefined;\n\t\t\tif (this._tasks.length > 0) {\n\t\t\t\tconst firstTask = this._tasks.peekStart()!;\n\t\t\t\tif (!this._currentTask) {\n\t\t\t\t\t// We're not currently executing a task, start executing the first one\n\t\t\t\t\tthis._currentTask = firstTask;\n\t\t\t\t} else if (\n\t\t\t\t\tthis._currentTask !== firstTask &&\n\t\t\t\t\tthis._currentTask.interrupt !==\n\t\t\t\t\t\tTaskInterruptBehavior.Forbidden\n\t\t\t\t) {\n\t\t\t\t\t// We are executing an interruptible task, and a new task with a higher priority was added\n\t\t\t\t\tif (\n\t\t\t\t\t\tthis._currentTask.interrupt ===\n\t\t\t\t\t\tTaskInterruptBehavior.Restart\n\t\t\t\t\t) {\n\t\t\t\t\t\t// The current task needs to be restarted after being interrupted, so reset it\n\t\t\t\t\t\tconst interrupted = this._currentTask;\n\t\t\t\t\t\tawait interrupted.reset();\n\t\t\t\t\t\t// Re-evaluate the queue if it changed during the reset\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tthis._currentTask !== interrupted ||\n\t\t\t\t\t\t\tthis._tasks.peekStart() !== firstTask\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t// switch to the new task\n\t\t\t\t\tthis._currentTask = firstTask;\n\t\t\t\t}\n\n\t\t\t\t// Capture the current task, so concurrent removals can be detected after each await\n\t\t\t\tconst task = this._currentTask;\n\n\t\t\t\tif (this.verbose) {\n\t\t\t\t\tconsole.log(`Stepping through task: ${getTaskName(task)}`);\n\t\t\t\t}\n\n\t\t\t\tconst finalizeCurrentTask = async () => {\n\t\t\t\t\tthis._tasks.remove(task);\n\t\t\t\t\t// Claim the task before awaiting, so a concurrent removeTasks() skips it\n\t\t\t\t\tthis._currentTask = undefined;\n\t\t\t\t\tawait task.reset();\n\t\t\t\t\t// Re-add the parent task to the list if there is one\n\t\t\t\t\tif (task.parent) {\n\t\t\t\t\t\tif (this.verbose) {\n\t\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t\t`Restoring parent task: ${getTaskName(\n\t\t\t\t\t\t\t\t\ttask.parent,\n\t\t\t\t\t\t\t\t)}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis._tasks.add(task.parent);\n\t\t\t\t\t}\n\t\t\t\t};\n\n\t\t\t\t// Execute the current task one step further\n\t\t\t\twaitFor = undefined;\n\t\t\t\tlet stepResult: TaskStepResult<unknown, TaskTag>;\n\t\t\t\ttry {\n\t\t\t\t\tstepResult = await task.step();\n\t\t\t\t} catch (e) {\n\t\t\t\t\t// Drop the error if the task was removed during the step. It was already rejected.\n\t\t\t\t\tif (this._currentTask !== task) continue;\n\n\t\t\t\t\tif (this.verbose) {\n\t\t\t\t\t\tconsole.error(`- Task threw an error:`, e);\n\t\t\t\t\t}\n\t\t\t\t\t// The task threw an error, expose the result and clean up.\n\t\t\t\t\ttask.reject(e as Error);\n\t\t\t\t\tawait finalizeCurrentTask();\n\t\t\t\t\t// Then continue with the next iteration\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// Drop the step result if the task was removed during the step. It was already rejected.\n\t\t\t\tif (this._currentTask !== task) continue;\n\n\t\t\t\tif (stepResult.newState === TaskState.Done) {\n\t\t\t\t\tif (this.verbose) {\n\t\t\t\t\t\tconsole.log(`- Task finished`);\n\t\t\t\t\t}\n\t\t\t\t\t// The task is done, clean up\n\t\t\t\t\ttask.resolve(stepResult.result);\n\t\t\t\t\tawait finalizeCurrentTask();\n\t\t\t\t\t// Then continue with the next iteration\n\t\t\t\t\tcontinue;\n\t\t\t\t} else if (stepResult.newState === TaskState.AwaitingPromise) {\n\t\t\t\t\t// The task is waiting for something\n\t\t\t\t\tif (this.verbose) {\n\t\t\t\t\t\tconsole.log(`- Task waiting`);\n\t\t\t\t\t}\n\n\t\t\t\t\t// If the task may be interrupted, check if there are other same-priority tasks that should be executed instead\n\t\t\t\t\tif (task.interrupt !== TaskInterruptBehavior.Forbidden) {\n\t\t\t\t\t\t// Re-queue the task, so the queue gets reordered\n\t\t\t\t\t\tthis._tasks.remove(task);\n\t\t\t\t\t\tthis._tasks.add(task);\n\n\t\t\t\t\t\tif (this._tasks.peekStart() !== task) {\n\t\t\t\t\t\t\tif (this.verbose) {\n\t\t\t\t\t\t\t\tconsole.log(`-- Continuing with another task`);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// The task is no longer the first in the queue. Switch to the other one\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// Otherwise, we got nothing to do right now than to wait\n\t\t\t\t\twaitFor = stepResult.promise;\n\t\t\t\t} else if (stepResult.newState === TaskState.AwaitingTask) {\n\t\t\t\t\t// The task spawned a sub-task. Replace it with the sub-task and continue executing\n\t\t\t\t\tif (this.verbose) {\n\t\t\t\t\t\tconsole.log(`- Task spawned a sub-task`);\n\t\t\t\t\t}\n\t\t\t\t\tthis._tasks.add(stepResult.task);\n\t\t\t\t\tthis._tasks.remove(task);\n\t\t\t\t\t// Continue with the next iteration\n\t\t\t\t\tcontinue;\n\t\t\t\t} else {\n\t\t\t\t\t// The current task is not done, or the step result is stale after a removal.\n\t\t\t\t\t// Continue with the next iteration.\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Task queue empty. Wait for either a new task or the stop signal,\n\t\t\t// or the current task to finish waiting\n\t\t\tthis._continueSignal = createDeferredPromise();\n\t\t\tconst nextAction = await Promise.race(\n\t\t\t\t[\n\t\t\t\t\tthis._continueSignal.then(() => \"continue\" as const),\n\t\t\t\t\tthis._stopSignal!.then(() => \"stop\" as const),\n\t\t\t\t\twaitFor?.then(() => \"continue\" as const),\n\t\t\t\t].filter((p) => p !== undefined),\n\t\t\t);\n\t\t\tthis._continueSignal = undefined;\n\t\t\tif (nextAction === \"stop\") break;\n\t\t}\n\t\tthis._stopPromise!.resolve();\n\t}\n\n\tpublic async stop(): Promise<void> {\n\t\tif (!this._stopSignal) return;\n\t\t// Signal to the task runner that it should stop\n\t\tthis._stopPromise = createDeferredPromise();\n\t\tthis._stopSignal.resolve();\n\t\tawait this._stopPromise;\n\t}\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;AACA;;;;;;;;AAAA,8BAGO;AACP,yBAA2B;AAC3B,6BAAsC;AACtC,mBAAqD;AAwCrD,SAAS,YAAY,MAAmB;AACvC,SAAO,GACN,KAAK,SAAS,KAAK,OAAO,KAAK,UAAU,KAAK,GAAG,MAAM,SACxD,QAAQ,KAAK,EAAE;AAChB;AAJS;AA+CT,SAAS,cAAiB,KAAQ;AACjC,SACC,OAAO,QAAQ,YACf,OAAO,IAAI,SAAS,cACpB,OAAO,IAAI,aAAa;AAE1B;AANS;AAgBT,IAAY;CAAZ,SAAYA,eAAY;AACvB,EAAAA,cAAAA,cAAA,SAAA,IAAA,CAAA,IAAA;AACA,EAAAA,cAAAA,cAAA,MAAA,IAAA,CAAA,IAAA;AACA,EAAAA,cAAAA,cAAA,QAAA,IAAA,CAAA,IAAA;AACA,EAAAA,cAAAA,cAAA,KAAA,IAAA,CAAA,IAAA;AACA,EAAAA,cAAAA,cAAA,OAAA,IAAA,CAAA,IAAA;AACA,EAAAA,cAAA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CAAC,KAAK;AAAa;AAEvB,SAAK,mBAAe,+CAAqB;AACzC,SAAK,YAAY,QAAO;AACxB,UAAM,KAAK;EACZ;;",
4
+ "sourcesContent": ["import type { CompareResult } from \"alcalzone-shared/comparable\";\nimport {\n\ttype DeferredPromise,\n\tcreateDeferredPromise,\n} from \"alcalzone-shared/deferred-promise\";\nimport { SortedList } from \"alcalzone-shared/sorted-list\";\nimport { createWrappingCounter } from \"./wrappingCounter.js\";\nimport { evalOrStatic, highResTimestamp, noop } from \"./utils.js\";\n\n/** The read-only view of a task that gets passed to its own task function */\nexport interface TaskHandle<TaskTag extends { id: string } = { id: string }> {\n\treadonly id: number;\n\treadonly timestamp: number;\n\n\t/** The parent task spawning this subtask, if any */\n\treadonly parent?: TaskHandle<TaskTag>;\n\n\t/** A name to identify the task */\n\treadonly name?: string;\n\t/** A tag to identify the task programmatically */\n\treadonly tag?: TaskTag;\n\t/** The task's priority */\n\treadonly priority: TaskPriority;\n\t/** The concurrency group this task belongs to */\n\treadonly group?: TaskConcurrencyGroup;\n\t/** How the task should behave when interrupted */\n\treadonly interrupt: TaskInterruptBehavior;\n\t/** The current state of the task */\n\tget state(): TaskState;\n}\n\n/** A high-level task that can be started and stepped through */\nexport interface Task<\n\tTReturn,\n\tTaskTag extends { id: string } = { id: string },\n\tTError extends Error = Error,\n> extends TaskHandle<TaskTag> {\n\treadonly builder: TaskBuilder<TReturn, TaskTag>;\n\n\t/** The parent task spawning this subtask, if any */\n\treadonly parent?: Task<unknown, TaskTag, TError>;\n\n\t/** Starts the task it if hasn't been started yet, and executes the next step of the task */\n\tstep(): Promise<TaskStepResult<TReturn, TaskTag>>;\n\t/** Stops the task without further executing it, cleans up, and prepares it for starting again */\n\treset(): Promise<void>;\n\t/** Resolves the task's promise to notify the caller */\n\tresolve(result: TReturn): void;\n\t/** Rejects the task's promise to notify the caller */\n\treject(error: TError): void;\n\n\treadonly generator: ReturnType<TaskBuilder<TReturn>[\"task\"]> | undefined;\n\treadonly promise: Promise<TReturn>;\n}\n\nfunction getTaskName(task: Task<unknown>): string {\n\treturn `${\n\t\ttask.name ?? (task.tag && JSON.stringify(task.tag)) ?? \"unnamed\"\n\t} (ID ${task.id})`;\n}\n\n/** Defines the necessary information for creating a task */\nexport interface TaskBuilder<\n\tTReturn,\n\tTaskTag extends { id: string } = { id: string },\n\tTInner = unknown,\n> {\n\t/** A name to identify the task */\n\tname?: string;\n\t/** A tag to identify the task programmatically */\n\ttag?: TaskTag;\n\t/** The task's priority */\n\tpriority: TaskPriority;\n\t/** How the task should behave when interrupted */\n\tinterrupt?: TaskInterruptBehavior;\n\t/** The concurrency group this task belongs to */\n\tgroup?: TaskConcurrencyGroup;\n\t/**\n\t * The task's main generator function. This is called repeatedly until it's done.\n\t * The function must yield at points where it may be interrupted.\n\t *\n\t * At those points, the task can also wait for something to happen:\n\t * - Either a Promise, in which case it must yield a function that returns that Promise\n\t * - Or another task, in which case it must yield a TaskBuilder object or a function that returns one\n\t *\n\t * Yielded Promises should not spawn new tasks. If they do, the spawned tasks MUST have a higher priority than the parent task.\n\t *\n\t * @param thisTask The task that runs this function. It is the same object the scheduler passes to `removeTasks` predicates,\n\t * so it can be compared by identity. It stays the same when the task gets restarted.\n\t */\n\ttask: (\n\t\tthisTask: TaskHandle,\n\t) => AsyncGenerator<\n\t\t| (() => Promise<unknown> | TaskBuilder<unknown, TaskTag, unknown>)\n\t\t| (() => TaskBuilder<unknown, TaskTag, unknown>)\n\t\t| TaskBuilder<unknown, TaskTag, unknown>\n\t\t| undefined,\n\t\tTReturn,\n\t\tTInner\n\t>;\n\t/** A cleanup function that gets called when the task is dropped */\n\tcleanup?: () => Promise<void>;\n}\n\nexport type TaskReturnType<T extends TaskBuilder<unknown>> =\n\tT extends TaskBuilder<infer R> ? R : never;\n\n/** Yields the given task, then each task waiting for it, up to the outermost one */\nfunction* selfAndParents<TaskTag extends { id: string }>(\n\ttask: Task<unknown, TaskTag>,\n): Generator<Task<unknown, TaskTag>> {\n\tfor (let t: Task<unknown, TaskTag> | undefined = task; t; t = t.parent) {\n\t\tyield t;\n\t}\n}\n\nfunction isTaskBuilder<T>(obj: any): obj is TaskBuilder<T> {\n\treturn (\n\t\ttypeof obj === \"object\" &&\n\t\ttypeof obj.task === \"function\" &&\n\t\ttypeof obj.priority === \"number\"\n\t);\n}\n\n/**\n * The priority of a task.\n *\n * Higher priority tasks are executed first and interrupt lower priority tasks.\n * The recommended priority for application-initiated communication is `Normal`.\n * `Low` and `Lower` are recommended for internal long-running tasks that should not interfere with user-initiated tasks.\n * `Idle` is recommended for tasks that should only run when no other tasks are pending.\n */\nexport enum TaskPriority {\n\tHighest,\n\tHigh = 1,\n\tNormal = 2,\n\tLow = 3,\n\tLower = 4,\n\tIdle = 5,\n}\n\nexport enum TaskState {\n\t/** The task has not been created yet */\n\tNone,\n\t/** The task is being executed */\n\tActive,\n\t/** The task is waiting for a Promise to resolve */\n\tAwaitingPromise,\n\t/** The task is waiting for another task to finish */\n\tAwaitingTask,\n\t/** The task is finished */\n\tDone,\n}\n\nexport enum TaskInterruptBehavior {\n\t/** The task may not be interrupted */\n\tForbidden,\n\t/** The task will be resumed after being interrupted (default) */\n\tResume,\n\t/** The task needs to be restarted after being interrupted */\n\tRestart,\n}\n\nexport type TaskStepResult<\n\tT,\n\tTaskTag extends { id: string } = { id: string },\n> =\n\t| {\n\t\t\tnewState: TaskState.Done;\n\t\t\tresult: T;\n\t }\n\t| {\n\t\t\tnewState: TaskState.Active;\n\t }\n\t| {\n\t\t\t// The task was reset while the step was in flight. The result is stale and must be dropped.\n\t\t\tnewState: TaskState.None;\n\t }\n\t| {\n\t\t\tnewState: TaskState.AwaitingPromise;\n\t\t\tpromise: Promise<unknown>;\n\t }\n\t| {\n\t\t\tnewState: TaskState.AwaitingTask;\n\t\t\ttask: Task<unknown, TaskTag>;\n\t };\n\n/** Identifies a concurrency group. Tasks within the same group cannot run concurrently. */\nexport interface TaskConcurrencyGroup {\n\tid: string;\n}\n\nfunction compareTasks<T1, T2>(a: Task<T1>, b: Task<T2>): CompareResult {\n\t// In the same concurrency group, only one task may be active at a time.\n\tconst aConcurrencyGroup = a.group?.id;\n\tconst bConcurrencyGroup = b.group?.id;\n\tif (\n\t\taConcurrencyGroup &&\n\t\tbConcurrencyGroup &&\n\t\taConcurrencyGroup === bConcurrencyGroup\n\t) {\n\t\tconst aActiveOrWaiting =\n\t\t\ta.state === TaskState.Active ||\n\t\t\ta.state === TaskState.AwaitingPromise ||\n\t\t\ta.state === TaskState.AwaitingTask;\n\t\tconst bActiveOrWaiting =\n\t\t\tb.state === TaskState.Active ||\n\t\t\tb.state === TaskState.AwaitingPromise ||\n\t\t\tb.state === TaskState.AwaitingTask;\n\n\t\tif (aActiveOrWaiting && !bActiveOrWaiting) return 1; // A is already active\n\t\tif (!aActiveOrWaiting && bActiveOrWaiting) return -1; // B is already active\n\n\t\t// None of the tasks is active, fall back to default sorting\n\t}\n\n\t// Sort by priority for tasks not in the same concurrency group\n\tif (a.priority < b.priority) return 1;\n\tif (a.priority > b.priority) return -1;\n\n\t// Deprioritize waiting tasks\n\tconst aWaiting =\n\t\ta.state === TaskState.AwaitingPromise ||\n\t\ta.state === TaskState.AwaitingTask;\n\tconst bWaiting =\n\t\tb.state === TaskState.AwaitingPromise ||\n\t\tb.state === TaskState.AwaitingTask;\n\tif (!aWaiting && bWaiting) return 1;\n\tif (aWaiting && !bWaiting) return -1;\n\n\t// Sort equal priority by timestamp. Newer tasks go to the end of the list\n\tif (a.timestamp < b.timestamp) return 1;\n\tif (a.timestamp > b.timestamp) return -1;\n\n\t// If all else fails, sort by ID\n\treturn Math.sign(b.id - a.id) as CompareResult;\n}\n\nexport class TaskScheduler<\n\tTaskTag extends { id: string } = { id: string },\n\tTError extends Error = Error,\n> {\n\tpublic constructor(\n\t\tprivate defaultErrorFactory: () => TError = () =>\n\t\t\tnew Error(\"Task was removed\") as any,\n\t\tprivate verbose: boolean = false,\n\t) {}\n\n\tprivate _tasks = new SortedList<Task<unknown, TaskTag>>(\n\t\tundefined,\n\t\tcompareTasks,\n\t);\n\tprivate _currentTask: Task<unknown, TaskTag> | undefined;\n\n\tprivate _idGenerator = createWrappingCounter(0xff_ff_ff);\n\tprivate _continueSignal: DeferredPromise<void> | undefined;\n\tprivate _stopSignal: DeferredPromise<void> | undefined;\n\tprivate _stopPromise: DeferredPromise<void> | undefined;\n\n\tpublic queueTask<T>(builder: TaskBuilder<T, TaskTag>): Promise<T> {\n\t\tconst task = this.createTask(builder);\n\t\tthis._tasks.add(task);\n\t\tif (this.verbose) {\n\t\t\tconsole.log(`Task queued: ${getTaskName(task)}`);\n\t\t}\n\n\t\tif (this._continueSignal) this._continueSignal.resolve();\n\t\treturn task.promise;\n\t}\n\n\t/**\n\t * Removes/stops tasks matching the given predicate. Returns `true` when a task was removed, `false` otherwise.\n\t *\n\t * The predicate also sees parent tasks that are waiting for a subtask.\n\t * Removing such a parent also removes the subtasks it is waiting for.\n\t */\n\tpublic async removeTasks(\n\t\tpredicate: (task: Task<unknown, TaskTag>) => boolean,\n\t\treason?: TError,\n\t): Promise<boolean> {\n\t\t// Collect tasks that should be removed, so that we handle the current task last.\n\t\t// Each queued task is the end of a chain of parents waiting for it.\n\t\tconst tasksToRemove = new Set<Task<unknown, TaskTag>>();\n\t\tconst currentTasksToRemove: Task<unknown, TaskTag>[] = [];\n\t\tfor (const queued of this._tasks) {\n\t\t\tfor (const task of selfAndParents(queued)) {\n\t\t\t\tif (!predicate(task)) continue;\n\t\t\t\tif (queued === this._currentTask) {\n\t\t\t\t\tcurrentTasksToRemove.push(task);\n\t\t\t\t} else {\n\t\t\t\t\ttasksToRemove.add(task);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (const task of currentTasksToRemove) {\n\t\t\ttasksToRemove.add(task);\n\t\t}\n\n\t\treason ??= this.defaultErrorFactory();\n\n\t\tfor (const task of tasksToRemove) {\n\t\t\t// Skip tasks the run loop finalized or that were dropped with an earlier chain\n\t\t\tconst leaf = this.findLeafTask(task);\n\t\t\tif (!leaf) continue;\n\n\t\t\t// Drop everything from the leaf up to the outermost matching parent\n\t\t\tlet outermost = task;\n\t\t\tfor (let t = task.parent; t; t = t.parent) {\n\t\t\t\tif (tasksToRemove.has(t)) outermost = t;\n\t\t\t}\n\t\t\tawait this.dropTasks(leaf, outermost, reason);\n\t\t}\n\n\t\tif (this._continueSignal) this._continueSignal.resolve();\n\n\t\treturn tasksToRemove.size > 0;\n\t}\n\n\t/** Returns the queued or current task that is `task` itself or one of its subtasks, if any */\n\tprivate findLeafTask(\n\t\ttask: Task<unknown, TaskTag>,\n\t): Task<unknown, TaskTag> | undefined {\n\t\tconst leaves = this._currentTask\n\t\t\t? [this._currentTask, ...this._tasks]\n\t\t\t: this._tasks;\n\t\tfor (const leaf of leaves) {\n\t\t\tfor (const t of selfAndParents(leaf)) {\n\t\t\t\tif (t === task) return leaf;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Removes `leaf` from the queue, then resets and rejects it and each of its parents up to and including `outermost`.\n\t * The parent of `outermost` is put back into the queue first.\n\t */\n\tprivate async dropTasks(\n\t\tleaf: Task<unknown, TaskTag>,\n\t\toutermost: Task<unknown, TaskTag>,\n\t\treason: TError,\n\t): Promise<void> {\n\t\tthis._tasks.remove(leaf);\n\t\t// Claim the task before awaiting anything, so the run loop drops the\n\t\t// result of an in-flight step instead of finalizing the task a second time\n\t\tif (this._currentTask === leaf) {\n\t\t\tthis._currentTask = undefined;\n\t\t}\n\t\tif (outermost.parent) this.restoreParentTask(outermost.parent);\n\t\tfor (let task = leaf; ; task = task.parent!) {\n\t\t\tif (this.verbose) {\n\t\t\t\tconsole.log(`Removing task: ${getTaskName(task)}`);\n\t\t\t}\n\t\t\tawait task.reset().catch(noop);\n\t\t\ttask.reject(reason);\n\t\t\tif (task === outermost) break;\n\t\t}\n\t}\n\n\t/**\n\t * Puts a parent back into the queue when its subtask is finished or removed.\n\t * Call this before cleaning up the subtask, so the parent can be found during the cleanup.\n\t */\n\tprivate restoreParentTask(parent: Task<unknown, TaskTag>): void {\n\t\tif (this.verbose) {\n\t\t\tconsole.log(`Restoring parent task: ${getTaskName(parent)}`);\n\t\t}\n\t\tthis._tasks.add(parent);\n\t}\n\n\t/**\n\t * Returns the promise of the first task matching the given predicate, if any.\n\t * The predicate also sees parent tasks that are waiting for a subtask.\n\t */\n\tpublic findTask<T = unknown>(\n\t\tpredicate: (task: Task<T, TaskTag>) => boolean,\n\t): Promise<T> | undefined {\n\t\tfor (const queued of this._tasks) {\n\t\t\tfor (const task of selfAndParents(queued)) {\n\t\t\t\tif (predicate(task as Task<T, TaskTag>)) {\n\t\t\t\t\treturn task.promise as Promise<T>;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Creates a task that can be executed */\n\tprivate createTask<T>(\n\t\tbuilder: TaskBuilder<T, TaskTag>,\n\t\tparent?: Task<unknown, TaskTag>,\n\t): Task<T, TaskTag, TError> {\n\t\tlet state = TaskState.None;\n\t\tlet generator: ReturnType<TaskBuilder<T, TaskTag>[\"task\"]> | undefined;\n\t\tlet waitForPromise: Promise<unknown> | undefined;\n\t\tconst promise = createDeferredPromise<T>();\n\n\t\tlet prevResult: unknown;\n\t\tlet waitError: unknown;\n\n\t\tconst self = this;\n\n\t\tconst task: Task<T, TaskTag, TError> = {\n\t\t\tid: this._idGenerator(),\n\t\t\ttimestamp: highResTimestamp(),\n\t\t\tbuilder,\n\t\t\tparent,\n\t\t\tname: builder.name,\n\t\t\ttag: builder.tag,\n\t\t\tpriority: builder.priority,\n\t\t\tgroup: builder.group,\n\t\t\tinterrupt: builder.interrupt ?? TaskInterruptBehavior.Resume,\n\t\t\tpromise,\n\t\t\tasync step() {\n\t\t\t\t// Do not proceed while still waiting for a Promise to resolve\n\t\t\t\tif (state === TaskState.AwaitingPromise && waitForPromise) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tnewState: state,\n\t\t\t\t\t\tpromise: waitForPromise,\n\t\t\t\t\t};\n\t\t\t\t} else if (state === TaskState.AwaitingTask) {\n\t\t\t\t\t// The scheduler puts a parent back into the queue before its subtask is cleaned up.\n\t\t\t\t\t// The parent must wait until it has received the subtask's result.\n\t\t\t\t\tif (waitForPromise) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tnewState: TaskState.AwaitingPromise,\n\t\t\t\t\t\t\tpromise: waitForPromise,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\"Cannot step through a task that is waiting for another task\",\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tgenerator ??= builder.task(task);\n\t\t\t\tstate = TaskState.Active;\n\n\t\t\t\t// Capture the generator so a concurrent reset() can be detected after the await\n\t\t\t\tconst gen = generator;\n\t\t\t\tlet genResult: Awaited<ReturnType<typeof gen.next>>;\n\t\t\t\ttry {\n\t\t\t\t\tgenResult = waitError\n\t\t\t\t\t\t? await gen.throw(waitError)\n\t\t\t\t\t\t: await gen.next(prevResult);\n\t\t\t\t} catch (e) {\n\t\t\t\t\t// Drop errors from a step whose task was reset in the meantime\n\t\t\t\t\tif (generator !== gen) return { newState: TaskState.None };\n\t\t\t\t\tthrow e;\n\t\t\t\t}\n\t\t\t\t// Drop the step result if the task was reset while the generator was running,\n\t\t\t\t// so the task state is not corrupted after the reset\n\t\t\t\tif (generator !== gen) return { newState: TaskState.None };\n\n\t\t\t\tconst { value, done } = genResult;\n\t\t\t\tprevResult = undefined;\n\t\t\t\twaitError = undefined;\n\t\t\t\tif (done) {\n\t\t\t\t\tstate = TaskState.Done;\n\t\t\t\t\treturn {\n\t\t\t\t\t\tnewState: state,\n\t\t\t\t\t\tresult: value,\n\t\t\t\t\t};\n\t\t\t\t} else if (value != undefined) {\n\t\t\t\t\tconst waitFor = evalOrStatic(value);\n\t\t\t\t\tif (waitFor instanceof Promise) {\n\t\t\t\t\t\tstate = TaskState.AwaitingPromise;\n\t\t\t\t\t\t// Ignore the promise's result if this task was reset in the meantime\n\t\t\t\t\t\twaitForPromise = waitFor\n\t\t\t\t\t\t\t.then((result) => {\n\t\t\t\t\t\t\t\tif (generator === gen) prevResult = result;\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t.catch((e) => {\n\t\t\t\t\t\t\t\tif (generator === gen) waitError = e;\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t.finally(() => {\n\t\t\t\t\t\t\t\tif (generator !== gen) return;\n\t\t\t\t\t\t\t\twaitForPromise = undefined;\n\t\t\t\t\t\t\t\tif (state === TaskState.AwaitingPromise) {\n\t\t\t\t\t\t\t\t\tstate = TaskState.Active;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tnewState: state,\n\t\t\t\t\t\t\tpromise: waitForPromise,\n\t\t\t\t\t\t};\n\t\t\t\t\t} else if (isTaskBuilder(waitFor)) {\n\t\t\t\t\t\tif (waitFor.priority > builder.priority) {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t\"Tasks cannot yield to tasks with lower priority than their own\",\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Create a sub-task with a reference to this task\n\t\t\t\t\t\tstate = TaskState.AwaitingTask;\n\t\t\t\t\t\tconst subTask = self.createTask(waitFor, this);\n\n\t\t\t\t\t\t// Ignore the subtask's result if this task was reset in the meantime\n\t\t\t\t\t\twaitForPromise = subTask.promise\n\t\t\t\t\t\t\t.then((result) => {\n\t\t\t\t\t\t\t\tif (generator === gen) prevResult = result;\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t.catch((e) => {\n\t\t\t\t\t\t\t\tif (generator === gen) waitError = e;\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t.finally(() => {\n\t\t\t\t\t\t\t\tif (generator !== gen) return;\n\t\t\t\t\t\t\t\twaitForPromise = undefined;\n\t\t\t\t\t\t\t\tif (state === TaskState.AwaitingTask) {\n\t\t\t\t\t\t\t\t\tstate = TaskState.Active;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tnewState: state,\n\t\t\t\t\t\t\ttask: subTask,\n\t\t\t\t\t\t};\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new Error(\"Invalid value yielded by task\");\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn { newState: state };\n\t\t\t\t}\n\t\t\t},\n\t\t\tasync reset() {\n\t\t\t\tif (state === TaskState.None) return;\n\t\t\t\tstate = TaskState.None;\n\t\t\t\twaitForPromise = undefined;\n\t\t\t\tgenerator = undefined;\n\t\t\t\tprevResult = undefined;\n\t\t\t\twaitError = undefined;\n\n\t\t\t\tawait builder.cleanup?.();\n\t\t\t},\n\t\t\tresolve(result) {\n\t\t\t\tpromise.resolve(result);\n\t\t\t},\n\t\t\treject(error) {\n\t\t\t\tpromise.reject(error);\n\t\t\t},\n\t\t\tget state() {\n\t\t\t\treturn state;\n\t\t\t},\n\t\t\tget generator() {\n\t\t\t\treturn generator;\n\t\t\t},\n\t\t};\n\t\treturn task;\n\t}\n\n\tpublic start(): void {\n\t\tthis._stopSignal = createDeferredPromise();\n\t\t// A timer instead of setImmediate, which only exists on Node.js and its clones\n\t\tsetTimeout(async () => {\n\t\t\ttry {\n\t\t\t\tawait this.run();\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error(\"Task runner crashed\", e);\n\t\t\t}\n\t\t}, 0);\n\t}\n\n\tprivate async run(): Promise<void> {\n\t\twhile (true) {\n\t\t\tlet waitFor: Promise<unknown> | undefined;\n\t\t\tif (this._tasks.length > 0) {\n\t\t\t\tconst firstTask = this._tasks.peekStart()!;\n\t\t\t\tif (!this._currentTask) {\n\t\t\t\t\t// We're not currently executing a task, start executing the first one\n\t\t\t\t\tthis._currentTask = firstTask;\n\t\t\t\t} else if (\n\t\t\t\t\tthis._currentTask !== firstTask &&\n\t\t\t\t\tthis._currentTask.interrupt !==\n\t\t\t\t\t\tTaskInterruptBehavior.Forbidden\n\t\t\t\t) {\n\t\t\t\t\t// We are executing an interruptible task, and a new task with a higher priority was added\n\t\t\t\t\tif (\n\t\t\t\t\t\tthis._currentTask.interrupt ===\n\t\t\t\t\t\tTaskInterruptBehavior.Restart\n\t\t\t\t\t) {\n\t\t\t\t\t\t// The current task needs to be restarted after being interrupted, so reset it\n\t\t\t\t\t\tconst interrupted = this._currentTask;\n\t\t\t\t\t\tawait interrupted.reset();\n\t\t\t\t\t\t// Re-evaluate the queue if it changed during the reset\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tthis._currentTask !== interrupted ||\n\t\t\t\t\t\t\tthis._tasks.peekStart() !== firstTask\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t// switch to the new task\n\t\t\t\t\tthis._currentTask = firstTask;\n\t\t\t\t}\n\n\t\t\t\t// Capture the current task, so concurrent removals can be detected after each await\n\t\t\t\tconst task = this._currentTask;\n\n\t\t\t\tif (this.verbose) {\n\t\t\t\t\tconsole.log(`Stepping through task: ${getTaskName(task)}`);\n\t\t\t\t}\n\n\t\t\t\tconst finalizeCurrentTask = async () => {\n\t\t\t\t\tthis._tasks.remove(task);\n\t\t\t\t\t// Claim the task before awaiting, so a concurrent removeTasks() skips it\n\t\t\t\t\tthis._currentTask = undefined;\n\t\t\t\t\tif (task.parent) this.restoreParentTask(task.parent);\n\t\t\t\t\tawait task.reset();\n\t\t\t\t};\n\n\t\t\t\t// Execute the current task one step further\n\t\t\t\twaitFor = undefined;\n\t\t\t\tlet stepResult: TaskStepResult<unknown, TaskTag>;\n\t\t\t\ttry {\n\t\t\t\t\tstepResult = await task.step();\n\t\t\t\t} catch (e) {\n\t\t\t\t\t// Drop the error if the task was removed during the step. It was already rejected.\n\t\t\t\t\tif (this._currentTask !== task) continue;\n\n\t\t\t\t\tif (this.verbose) {\n\t\t\t\t\t\tconsole.error(`- Task threw an error:`, e);\n\t\t\t\t\t}\n\t\t\t\t\t// The task threw an error, expose the result and clean up.\n\t\t\t\t\ttask.reject(e as Error);\n\t\t\t\t\tawait finalizeCurrentTask();\n\t\t\t\t\t// Then continue with the next iteration\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// Drop the step result if the task was removed during the step. It was already rejected.\n\t\t\t\tif (this._currentTask !== task) continue;\n\n\t\t\t\tif (stepResult.newState === TaskState.Done) {\n\t\t\t\t\tif (this.verbose) {\n\t\t\t\t\t\tconsole.log(`- Task finished`);\n\t\t\t\t\t}\n\t\t\t\t\t// The task is done, clean up\n\t\t\t\t\ttask.resolve(stepResult.result);\n\t\t\t\t\tawait finalizeCurrentTask();\n\t\t\t\t\t// Then continue with the next iteration\n\t\t\t\t\tcontinue;\n\t\t\t\t} else if (stepResult.newState === TaskState.AwaitingPromise) {\n\t\t\t\t\t// The task is waiting for something\n\t\t\t\t\tif (this.verbose) {\n\t\t\t\t\t\tconsole.log(`- Task waiting`);\n\t\t\t\t\t}\n\n\t\t\t\t\t// If the task may be interrupted, check if there are other same-priority tasks that should be executed instead\n\t\t\t\t\tif (task.interrupt !== TaskInterruptBehavior.Forbidden) {\n\t\t\t\t\t\t// Re-queue the task, so the queue gets reordered\n\t\t\t\t\t\tthis._tasks.remove(task);\n\t\t\t\t\t\tthis._tasks.add(task);\n\n\t\t\t\t\t\tif (this._tasks.peekStart() !== task) {\n\t\t\t\t\t\t\tif (this.verbose) {\n\t\t\t\t\t\t\t\tconsole.log(`-- Continuing with another task`);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// The task is no longer the first in the queue. Switch to the other one\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// Otherwise, we got nothing to do right now than to wait\n\t\t\t\t\twaitFor = stepResult.promise;\n\t\t\t\t} else if (stepResult.newState === TaskState.AwaitingTask) {\n\t\t\t\t\t// The task spawned a sub-task. Replace it with the sub-task and continue executing\n\t\t\t\t\tif (this.verbose) {\n\t\t\t\t\t\tconsole.log(`- Task spawned a sub-task`);\n\t\t\t\t\t}\n\t\t\t\t\tthis._tasks.add(stepResult.task);\n\t\t\t\t\tthis._tasks.remove(task);\n\t\t\t\t\t// Switching to the subtask must not count as interrupting the parent\n\t\t\t\t\tthis._currentTask = undefined;\n\t\t\t\t\t// Continue with the next iteration\n\t\t\t\t\tcontinue;\n\t\t\t\t} else {\n\t\t\t\t\t// The current task is not done, or the step result is stale after a removal.\n\t\t\t\t\t// Continue with the next iteration.\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Task queue empty. Wait for either a new task or the stop signal,\n\t\t\t// or the current task to finish waiting\n\t\t\tthis._continueSignal = createDeferredPromise();\n\t\t\tconst nextAction = await Promise.race(\n\t\t\t\t[\n\t\t\t\t\tthis._continueSignal.then(() => \"continue\" as const),\n\t\t\t\t\tthis._stopSignal!.then(() => \"stop\" as const),\n\t\t\t\t\twaitFor?.then(() => \"continue\" as const),\n\t\t\t\t].filter((p) => p !== undefined),\n\t\t\t);\n\t\t\tthis._continueSignal = undefined;\n\t\t\tif (nextAction === \"stop\") break;\n\t\t}\n\t\tthis._stopPromise!.resolve();\n\t}\n\n\tpublic async stop(): Promise<void> {\n\t\tif (!this._stopSignal) return;\n\t\t// Signal to the task runner that it should stop\n\t\tthis._stopPromise = createDeferredPromise();\n\t\tthis._stopSignal.resolve();\n\t\tawait this._stopPromise;\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;AACA;;;;;;;;AAAA,8BAGO;AACP,yBAA2B;AAC3B,6BAAsC;AACtC,mBAAqD;AAgDrD,SAAS,YAAY,MAAmB;AACvC,SAAO,GACN,KAAK,SAAS,KAAK,OAAO,KAAK,UAAU,KAAK,GAAG,MAAM,SACxD,QAAQ,KAAK,EAAE;AAChB;AAJS;AAqDT,UAAU,eACT,MA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AEO,MAAM,OAAI;AAChB,QAAI,CAAC,KAAK;AAAa;AAEvB,SAAK,mBAAe,+CAAqB;AACzC,SAAK,YAAY,QAAO;AACxB,UAAM,KAAK;EACZ;;",
6
6
  "names": ["TaskPriority", "TaskState", "TaskInterruptBehavior"]
7
7
  }
@@ -1,3 +1,3 @@
1
- export { type Task, type TaskBuilder, TaskInterruptBehavior, TaskPriority, type TaskReturnType, TaskScheduler, TaskState, type TaskStepResult, type TaskConcurrencyGroup, } from "./Task.js";
1
+ export { type Task, type TaskBuilder, type TaskHandle, TaskInterruptBehavior, TaskPriority, type TaskReturnType, TaskScheduler, TaskState, type TaskStepResult, type TaskConcurrencyGroup, } from "./Task.js";
2
2
  export { waitFor, type WaitForReturnType } from "./utils.js";
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
- "sourcesContent": ["export {\n\ttype Task,\n\ttype TaskBuilder,\n\tTaskInterruptBehavior,\n\tTaskPriority,\n\ttype TaskReturnType,\n\tTaskScheduler,\n\tTaskState,\n\ttype TaskStepResult,\n\ttype TaskConcurrencyGroup,\n} from \"./Task.js\";\nexport { waitFor, type WaitForReturnType } from \"./utils.js\";\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;AAAA,kBAUO;AACP,mBAAgD;",
4
+ "sourcesContent": ["export {\n\ttype Task,\n\ttype TaskBuilder,\n\ttype TaskHandle,\n\tTaskInterruptBehavior,\n\tTaskPriority,\n\ttype TaskReturnType,\n\tTaskScheduler,\n\tTaskState,\n\ttype TaskStepResult,\n\ttype TaskConcurrencyGroup,\n} from \"./Task.js\";\nexport { waitFor, type WaitForReturnType } from \"./utils.js\";\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;AAAA,kBAWO;AACP,mBAAgD;",
6
6
  "names": []
7
7
  }
@@ -1,14 +1,13 @@
1
- /** A high-level task that can be started and stepped through */
2
- export interface Task<TReturn, TaskTag extends {
1
+ /** The read-only view of a task that gets passed to its own task function */
2
+ export interface TaskHandle<TaskTag extends {
3
3
  id: string;
4
4
  } = {
5
5
  id: string;
6
- }, TError extends Error = Error> {
6
+ }> {
7
7
  readonly id: number;
8
8
  readonly timestamp: number;
9
- readonly builder: TaskBuilder<TReturn, TaskTag>;
10
9
  /** The parent task spawning this subtask, if any */
11
- readonly parent?: Task<unknown, TaskTag, TError>;
10
+ readonly parent?: TaskHandle<TaskTag>;
12
11
  /** A name to identify the task */
13
12
  readonly name?: string;
14
13
  /** A tag to identify the task programmatically */
@@ -19,6 +18,18 @@ export interface Task<TReturn, TaskTag extends {
19
18
  readonly group?: TaskConcurrencyGroup;
20
19
  /** How the task should behave when interrupted */
21
20
  readonly interrupt: TaskInterruptBehavior;
21
+ /** The current state of the task */
22
+ get state(): TaskState;
23
+ }
24
+ /** A high-level task that can be started and stepped through */
25
+ export interface Task<TReturn, TaskTag extends {
26
+ id: string;
27
+ } = {
28
+ id: string;
29
+ }, TError extends Error = Error> extends TaskHandle<TaskTag> {
30
+ readonly builder: TaskBuilder<TReturn, TaskTag>;
31
+ /** The parent task spawning this subtask, if any */
32
+ readonly parent?: Task<unknown, TaskTag, TError>;
22
33
  /** Starts the task it if hasn't been started yet, and executes the next step of the task */
23
34
  step(): Promise<TaskStepResult<TReturn, TaskTag>>;
24
35
  /** Stops the task without further executing it, cleans up, and prepares it for starting again */
@@ -27,8 +38,6 @@ export interface Task<TReturn, TaskTag extends {
27
38
  resolve(result: TReturn): void;
28
39
  /** Rejects the task's promise to notify the caller */
29
40
  reject(error: TError): void;
30
- /** The current state of the task */
31
- get state(): TaskState;
32
41
  readonly generator: ReturnType<TaskBuilder<TReturn>["task"]> | undefined;
33
42
  readonly promise: Promise<TReturn>;
34
43
  }
@@ -57,8 +66,11 @@ export interface TaskBuilder<TReturn, TaskTag extends {
57
66
  * - Or another task, in which case it must yield a TaskBuilder object or a function that returns one
58
67
  *
59
68
  * Yielded Promises should not spawn new tasks. If they do, the spawned tasks MUST have a higher priority than the parent task.
69
+ *
70
+ * @param thisTask The task that runs this function. It is the same object the scheduler passes to `removeTasks` predicates,
71
+ * so it can be compared by identity. It stays the same when the task gets restarted.
60
72
  */
61
- task: () => AsyncGenerator<(() => Promise<unknown> | TaskBuilder<unknown, TaskTag, unknown>) | (() => TaskBuilder<unknown, TaskTag, unknown>) | TaskBuilder<unknown, TaskTag, unknown> | undefined, TReturn, TInner>;
73
+ task: (thisTask: TaskHandle) => AsyncGenerator<(() => Promise<unknown> | TaskBuilder<unknown, TaskTag, unknown>) | (() => TaskBuilder<unknown, TaskTag, unknown>) | TaskBuilder<unknown, TaskTag, unknown> | undefined, TReturn, TInner>;
62
74
  /** A cleanup function that gets called when the task is dropped */
63
75
  cleanup?: () => Promise<void>;
64
76
  }
@@ -136,10 +148,29 @@ export declare class TaskScheduler<TaskTag extends {
136
148
  private _stopSignal;
137
149
  private _stopPromise;
138
150
  queueTask<T>(builder: TaskBuilder<T, TaskTag>): Promise<T>;
139
- /** Removes/stops tasks matching the given predicate. Returns `true` when a task was removed, `false` otherwise. */
151
+ /**
152
+ * Removes/stops tasks matching the given predicate. Returns `true` when a task was removed, `false` otherwise.
153
+ *
154
+ * The predicate also sees parent tasks that are waiting for a subtask.
155
+ * Removing such a parent also removes the subtasks it is waiting for.
156
+ */
140
157
  removeTasks(predicate: (task: Task<unknown, TaskTag>) => boolean, reason?: TError): Promise<boolean>;
141
- /** Removes a single task from the queue, resets it and rejects its promise */
142
- private dropTask;
158
+ /** Returns the queued or current task that is `task` itself or one of its subtasks, if any */
159
+ private findLeafTask;
160
+ /**
161
+ * Removes `leaf` from the queue, then resets and rejects it and each of its parents up to and including `outermost`.
162
+ * The parent of `outermost` is put back into the queue first.
163
+ */
164
+ private dropTasks;
165
+ /**
166
+ * Puts a parent back into the queue when its subtask is finished or removed.
167
+ * Call this before cleaning up the subtask, so the parent can be found during the cleanup.
168
+ */
169
+ private restoreParentTask;
170
+ /**
171
+ * Returns the promise of the first task matching the given predicate, if any.
172
+ * The predicate also sees parent tasks that are waiting for a subtask.
173
+ */
143
174
  findTask<T = unknown>(predicate: (task: Task<T, TaskTag>) => boolean): Promise<T> | undefined;
144
175
  /** Creates a task that can be executed */
145
176
  private createTask;
@@ -1 +1 @@
1
- {"version":3,"file":"Task.d.ts","sourceRoot":"","sources":["../../src/Task.ts"],"names":[],"mappings":"AASA,gEAAgE;AAChE,MAAM,WAAW,IAAI,CACpB,OAAO,EACP,OAAO,SAAS;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,EAC/C,MAAM,SAAS,KAAK,GAAG,KAAK;IAE5B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAEhD,oDAAoD;IACpD,QAAQ,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IAEjD,kCAAkC;IAClC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,kDAAkD;IAClD,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;IACvB,0BAA0B;IAC1B,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;IAChC,iDAAiD;IACjD,QAAQ,CAAC,KAAK,CAAC,EAAE,oBAAoB,CAAC;IACtC,kDAAkD;IAClD,QAAQ,CAAC,SAAS,EAAE,qBAAqB,CAAC;IAC1C,4FAA4F;IAC5F,IAAI,IAAI,OAAO,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;IAClD,iGAAiG;IACjG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,uDAAuD;IACvD,OAAO,CAAC,M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7B,OAAO,GAAE,OAAe;IAGjC,OAAO,CAAC,MAAM,CAGZ;IACF,OAAO,CAAC,YAAY,CAAqC;IAEzD,OAAO,CAAC,YAAY,CAAqC;IACzD,OAAO,CAAC,eAAe,CAAoC;IAC3D,OAAO,CAAC,WAAW,CAAoC;IACvD,OAAO,CAAC,YAAY,CAAoC;IAEjD,SAAS,CAAC,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAWjE;;;;;OAKG;IACU,WAAW,CACvB,SAAS,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,OAAO,EACpD,MAAM,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,OAAO,CAAC;IAuCnB,8FAA8F;IAC9F,OAAO,CAAC,YAAY;IAapB;;;OAGG;YACW,SAAS;IAsBvB;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAOzB;;;OAGG;IACI,QAAQ,CAAC,CAAC,GAAG,OAAO,EAC1B,SAAS,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,KAAK,OAAO,GAC5C,OAAO,CAAC,CAAC,CAAC,GAAG,SAAS;IAUzB,0CAA0C;IAC1C,OAAO,CAAC,UAAU;IAgKX,KAAK,IAAI,IAAI;YAYN,GAAG;IAwIJ,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAOlC"}
package/build/esm/Task.js CHANGED
@@ -5,6 +5,12 @@ import { evalOrStatic, highResTimestamp, noop } from "./utils.js";
5
5
  function getTaskName(task) {
6
6
  return `${task.name ?? (task.tag && JSON.stringify(task.tag)) ?? "unnamed"} (ID ${task.id})`;
7
7
  }
8
+ /** Yields the given task, then each task waiting for it, up to the outermost one */
9
+ function* selfAndParents(task) {
10
+ for (let t = task; t; t = t.parent) {
11
+ yield t;
12
+ }
13
+ }
8
14
  function isTaskBuilder(obj) {
9
15
  return (typeof obj === "object" &&
10
16
  typeof obj.task === "function" &&
@@ -113,59 +119,107 @@ export class TaskScheduler {
113
119
  this._continueSignal.resolve();
114
120
  return task.promise;
115
121
  }
116
- /** Removes/stops tasks matching the given predicate. Returns `true` when a task was removed, `false` otherwise. */
122
+ /**
123
+ * Removes/stops tasks matching the given predicate. Returns `true` when a task was removed, `false` otherwise.
124
+ *
125
+ * The predicate also sees parent tasks that are waiting for a subtask.
126
+ * Removing such a parent also removes the subtasks it is waiting for.
127
+ */
117
128
  async removeTasks(predicate, reason) {
118
- // Collect tasks that should be removed, so that we handle the current task last
119
- const tasksToRemove = [];
120
- let currentTaskToRemove;
121
- for (const task of this._tasks) {
122
- if (predicate(task)) {
123
- if (task === this._currentTask) {
124
- currentTaskToRemove = task;
129
+ // Collect tasks that should be removed, so that we handle the current task last.
130
+ // Each queued task is the end of a chain of parents waiting for it.
131
+ const tasksToRemove = new Set();
132
+ const currentTasksToRemove = [];
133
+ for (const queued of this._tasks) {
134
+ for (const task of selfAndParents(queued)) {
135
+ if (!predicate(task))
136
+ continue;
137
+ if (queued === this._currentTask) {
138
+ currentTasksToRemove.push(task);
125
139
  }
126
140
  else {
127
- tasksToRemove.push(task);
141
+ tasksToRemove.add(task);
128
142
  }
129
143
  }
130
144
  }
131
- if (currentTaskToRemove) {
132
- tasksToRemove.push(currentTaskToRemove);
145
+ for (const task of currentTasksToRemove) {
146
+ tasksToRemove.add(task);
133
147
  }
134
148
  reason ??= this.defaultErrorFactory();
135
149
  for (const task of tasksToRemove) {
136
- // Skip tasks the run loop finalized during a previous iteration's await
137
- if (this._currentTask !== task && !this._tasks.contains(task)) {
150
+ // Skip tasks the run loop finalized or that were dropped with an earlier chain
151
+ const leaf = this.findLeafTask(task);
152
+ if (!leaf)
138
153
  continue;
154
+ // Drop everything from the leaf up to the outermost matching parent
155
+ let outermost = task;
156
+ for (let t = task.parent; t; t = t.parent) {
157
+ if (tasksToRemove.has(t))
158
+ outermost = t;
139
159
  }
140
- await this.dropTask(task, reason);
160
+ await this.dropTasks(leaf, outermost, reason);
141
161
  }
142
162
  if (this._continueSignal)
143
163
  this._continueSignal.resolve();
144
- return tasksToRemove.length > 0;
164
+ return tasksToRemove.size > 0;
145
165
  }
146
- /** Removes a single task from the queue, resets it and rejects its promise */
147
- async dropTask(task, reason) {
148
- if (this.verbose) {
149
- console.log(`Removing task: ${getTaskName(task)}`);
166
+ /** Returns the queued or current task that is `task` itself or one of its subtasks, if any */
167
+ findLeafTask(task) {
168
+ const leaves = this._currentTask
169
+ ? [this._currentTask, ...this._tasks]
170
+ : this._tasks;
171
+ for (const leaf of leaves) {
172
+ for (const t of selfAndParents(leaf)) {
173
+ if (t === task)
174
+ return leaf;
175
+ }
150
176
  }
151
- this._tasks.remove(task);
177
+ }
178
+ /**
179
+ * Removes `leaf` from the queue, then resets and rejects it and each of its parents up to and including `outermost`.
180
+ * The parent of `outermost` is put back into the queue first.
181
+ */
182
+ async dropTasks(leaf, outermost, reason) {
183
+ this._tasks.remove(leaf);
152
184
  // Claim the task before awaiting anything, so the run loop drops the
153
185
  // result of an in-flight step instead of finalizing the task a second time
154
- if (this._currentTask === task) {
186
+ if (this._currentTask === leaf) {
155
187
  this._currentTask = undefined;
156
188
  }
157
- await task.reset().catch(noop);
158
- task.reject(reason);
159
- // Re-add the parent task to the list if there is one
160
- if (task.parent) {
189
+ if (outermost.parent)
190
+ this.restoreParentTask(outermost.parent);
191
+ for (let task = leaf;; task = task.parent) {
161
192
  if (this.verbose) {
162
- console.log(`Restoring parent task: ${getTaskName(task.parent)}`);
193
+ console.log(`Removing task: ${getTaskName(task)}`);
163
194
  }
164
- this._tasks.add(task.parent);
195
+ await task.reset().catch(noop);
196
+ task.reject(reason);
197
+ if (task === outermost)
198
+ break;
165
199
  }
166
200
  }
201
+ /**
202
+ * Puts a parent back into the queue when its subtask is finished or removed.
203
+ * Call this before cleaning up the subtask, so the parent can be found during the cleanup.
204
+ */
205
+ restoreParentTask(parent) {
206
+ if (this.verbose) {
207
+ console.log(`Restoring parent task: ${getTaskName(parent)}`);
208
+ }
209
+ this._tasks.add(parent);
210
+ }
211
+ /**
212
+ * Returns the promise of the first task matching the given predicate, if any.
213
+ * The predicate also sees parent tasks that are waiting for a subtask.
214
+ */
167
215
  findTask(predicate) {
168
- return this._tasks.find((t) => predicate(t))?.promise;
216
+ for (const queued of this._tasks) {
217
+ for (const task of selfAndParents(queued)) {
218
+ if (predicate(task)) {
219
+ return task.promise;
220
+ }
221
+ }
222
+ }
169
223
  }
170
224
  /** Creates a task that can be executed */
171
225
  createTask(builder, parent) {
@@ -176,7 +230,7 @@ export class TaskScheduler {
176
230
  let prevResult;
177
231
  let waitError;
178
232
  const self = this;
179
- return {
233
+ const task = {
180
234
  id: this._idGenerator(),
181
235
  timestamp: highResTimestamp(),
182
236
  builder,
@@ -196,9 +250,17 @@ export class TaskScheduler {
196
250
  };
197
251
  }
198
252
  else if (state === TaskState.AwaitingTask) {
253
+ // The scheduler puts a parent back into the queue before its subtask is cleaned up.
254
+ // The parent must wait until it has received the subtask's result.
255
+ if (waitForPromise) {
256
+ return {
257
+ newState: TaskState.AwaitingPromise,
258
+ promise: waitForPromise,
259
+ };
260
+ }
199
261
  throw new Error("Cannot step through a task that is waiting for another task");
200
262
  }
201
- generator ??= builder.task();
263
+ generator ??= builder.task(task);
202
264
  state = TaskState.Active;
203
265
  // Capture the generator so a concurrent reset() can be detected after the await
204
266
  const gen = generator;
@@ -232,14 +294,19 @@ export class TaskScheduler {
232
294
  const waitFor = evalOrStatic(value);
233
295
  if (waitFor instanceof Promise) {
234
296
  state = TaskState.AwaitingPromise;
297
+ // Ignore the promise's result if this task was reset in the meantime
235
298
  waitForPromise = waitFor
236
299
  .then((result) => {
237
- prevResult = result;
300
+ if (generator === gen)
301
+ prevResult = result;
238
302
  })
239
303
  .catch((e) => {
240
- waitError = e;
304
+ if (generator === gen)
305
+ waitError = e;
241
306
  })
242
307
  .finally(() => {
308
+ if (generator !== gen)
309
+ return;
243
310
  waitForPromise = undefined;
244
311
  if (state === TaskState.AwaitingPromise) {
245
312
  state = TaskState.Active;
@@ -257,14 +324,20 @@ export class TaskScheduler {
257
324
  // Create a sub-task with a reference to this task
258
325
  state = TaskState.AwaitingTask;
259
326
  const subTask = self.createTask(waitFor, this);
260
- subTask.promise
327
+ // Ignore the subtask's result if this task was reset in the meantime
328
+ waitForPromise = subTask.promise
261
329
  .then((result) => {
262
- prevResult = result;
330
+ if (generator === gen)
331
+ prevResult = result;
263
332
  })
264
333
  .catch((e) => {
265
- waitError = e;
334
+ if (generator === gen)
335
+ waitError = e;
266
336
  })
267
337
  .finally(() => {
338
+ if (generator !== gen)
339
+ return;
340
+ waitForPromise = undefined;
268
341
  if (state === TaskState.AwaitingTask) {
269
342
  state = TaskState.Active;
270
343
  }
@@ -305,6 +378,7 @@ export class TaskScheduler {
305
378
  return generator;
306
379
  },
307
380
  };
381
+ return task;
308
382
  }
309
383
  start() {
310
384
  this._stopSignal = createDeferredPromise();
@@ -354,14 +428,9 @@ export class TaskScheduler {
354
428
  this._tasks.remove(task);
355
429
  // Claim the task before awaiting, so a concurrent removeTasks() skips it
356
430
  this._currentTask = undefined;
431
+ if (task.parent)
432
+ this.restoreParentTask(task.parent);
357
433
  await task.reset();
358
- // Re-add the parent task to the list if there is one
359
- if (task.parent) {
360
- if (this.verbose) {
361
- console.log(`Restoring parent task: ${getTaskName(task.parent)}`);
362
- }
363
- this._tasks.add(task.parent);
364
- }
365
434
  };
366
435
  // Execute the current task one step further
367
436
  waitFor = undefined;
@@ -423,6 +492,8 @@ export class TaskScheduler {
423
492
  }
424
493
  this._tasks.add(stepResult.task);
425
494
  this._tasks.remove(task);
495
+ // Switching to the subtask must not count as interrupting the parent
496
+ this._currentTask = undefined;
426
497
  // Continue with the next iteration
427
498
  continue;
428
499
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Task.js","sourceRoot":"","sources":["../../src/Task.ts"],"names":[],"mappings":"AACA,OAAO,EAEN,qBAAqB,GACrB,M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AC,WAAY,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,MAAe,CAAC;gBAC7C,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,UAAmB,CAAC;aACxC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAChC,CAAC;YACF,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;YACjC,IAAI,UAAU,KAAK,MAAM;gBAAE,MAAM;QAClC,CAAC;QACD,IAAI,CAAC,YAAa,CAAC,OAAO,EAAE,CAAC;IAC9B,CAAC;IAEM,KAAK,CAAC,IAAI;QAChB,IAAI,CAAC,IAAI,CAAC,WAAW;YAAE,OAAO;QAC9B,gDAAgD;QAChD,IAAI,CAAC,YAAY,GAAG,qBAAqB,EAAE,CAAC;QAC5C,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;QAC3B,MAAM,IAAI,CAAC,YAAY,CAAC;IACzB,CAAC;CACD"}
@@ -1,3 +1,3 @@
1
- export { type Task, type TaskBuilder, TaskInterruptBehavior, TaskPriority, type TaskReturnType, TaskScheduler, TaskState, type TaskStepResult, type TaskConcurrencyGroup, } from "./Task.js";
1
+ export { type Task, type TaskBuilder, type TaskHandle, TaskInterruptBehavior, TaskPriority, type TaskReturnType, TaskScheduler, TaskState, type TaskStepResult, type TaskConcurrencyGroup, } from "./Task.js";
2
2
  export { waitFor, type WaitForReturnType } from "./utils.js";
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,IAAI,EACT,KAAK,WAAW,EAChB,qBAAqB,EACrB,YAAY,EACZ,KAAK,cAAc,EACnB,aAAa,EACb,SAAS,EACT,KAAK,cAAc,EACnB,KAAK,oBAAoB,GACzB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,IAAI,EACT,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,qBAAqB,EACrB,YAAY,EACZ,KAAK,cAAc,EACnB,aAAa,EACb,SAAS,EACT,KAAK,cAAc,EACnB,KAAK,oBAAoB,GACzB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,YAAY,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,qBAAqB,EACrB,YAAY,EAEZ,aAAa,EACb,SAAS,GAGT,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,OAAO,EAA0B,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,qBAAqB,EACrB,YAAY,EAEZ,aAAa,EACb,SAAS,GAGT,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,OAAO,EAA0B,MAAM,YAAY,CAAC"}
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "description": "A cooperative task scheduler based on generator functions",
7
- "version": "1.2.3",
7
+ "version": "1.3.1",
8
8
  "license": "MIT",
9
9
  "type": "module",
10
10
  "module": "build/index.js",