@zwave-js/waddle 1.0.0
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/LICENSE +21 -0
- package/README.md +425 -0
- package/build/cjs/Task.d.ts +138 -0
- package/build/cjs/Task.js +375 -0
- package/build/cjs/Task.js.map +7 -0
- package/build/cjs/index.d.ts +2 -0
- package/build/cjs/index.js +35 -0
- package/build/cjs/index.js.map +7 -0
- package/build/cjs/package.json +3 -0
- package/build/cjs/utils.d.ts +8 -0
- package/build/cjs/utils.js +51 -0
- package/build/cjs/utils.js.map +7 -0
- package/build/cjs/wrappingCounter.d.ts +7 -0
- package/build/cjs/wrappingCounter.js +39 -0
- package/build/cjs/wrappingCounter.js.map +7 -0
- package/build/esm/Task.d.ts +138 -0
- package/build/esm/Task.d.ts.map +1 -0
- package/build/esm/Task.js +413 -0
- package/build/esm/Task.js.map +1 -0
- package/build/esm/index.d.ts +2 -0
- package/build/esm/index.d.ts.map +1 -0
- package/build/esm/index.js +2 -0
- package/build/esm/index.js.map +1 -0
- package/build/esm/package.json +3 -0
- package/build/esm/utils.d.ts +8 -0
- package/build/esm/utils.d.ts.map +1 -0
- package/build/esm/utils.js +22 -0
- package/build/esm/utils.js.map +1 -0
- package/build/esm/wrappingCounter.d.ts +7 -0
- package/build/esm/wrappingCounter.d.ts.map +1 -0
- package/build/esm/wrappingCounter.js +15 -0
- package/build/esm/wrappingCounter.js.map +1 -0
- package/package.json +41 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/** A high-level task that can be started and stepped through */
|
|
2
|
+
export interface Task<TReturn, TaskTag extends {
|
|
3
|
+
id: string;
|
|
4
|
+
} = {
|
|
5
|
+
id: string;
|
|
6
|
+
}, TError extends Error = Error> {
|
|
7
|
+
readonly id: number;
|
|
8
|
+
readonly timestamp: number;
|
|
9
|
+
readonly builder: TaskBuilder<TReturn, TaskTag>;
|
|
10
|
+
/** The parent task spawning this subtask, if any */
|
|
11
|
+
readonly parent?: Task<unknown, TaskTag, TError>;
|
|
12
|
+
/** A name to identify the task */
|
|
13
|
+
readonly name?: string;
|
|
14
|
+
/** A tag to identify the task programmatically */
|
|
15
|
+
readonly tag?: TaskTag;
|
|
16
|
+
/** The task's priority */
|
|
17
|
+
readonly priority: TaskPriority;
|
|
18
|
+
/** How the task should behave when interrupted */
|
|
19
|
+
readonly interrupt: TaskInterruptBehavior;
|
|
20
|
+
/** Starts the task it if hasn't been started yet, and executes the next step of the task */
|
|
21
|
+
step(): Promise<TaskStepResult<TReturn, TaskTag>>;
|
|
22
|
+
/** Stops the task without further executing it, cleans up, and prepares it for starting again */
|
|
23
|
+
reset(): Promise<void>;
|
|
24
|
+
/** Resolves the task's promise to notify the caller */
|
|
25
|
+
resolve(result: TReturn): void;
|
|
26
|
+
/** Rejects the task's promise to notify the caller */
|
|
27
|
+
reject(error: TError): void;
|
|
28
|
+
/** The current state of the task */
|
|
29
|
+
get state(): TaskState;
|
|
30
|
+
readonly generator: ReturnType<TaskBuilder<TReturn>["task"]> | undefined;
|
|
31
|
+
readonly promise: Promise<TReturn>;
|
|
32
|
+
}
|
|
33
|
+
/** Defines the necessary information for creating a task */
|
|
34
|
+
export interface TaskBuilder<TReturn, TaskTag extends {
|
|
35
|
+
id: string;
|
|
36
|
+
} = {
|
|
37
|
+
id: string;
|
|
38
|
+
}, TInner = unknown> {
|
|
39
|
+
/** A name to identify the task */
|
|
40
|
+
name?: string;
|
|
41
|
+
/** A tag to identify the task programmatically */
|
|
42
|
+
tag?: TaskTag;
|
|
43
|
+
/** The task's priority */
|
|
44
|
+
priority: TaskPriority;
|
|
45
|
+
/** How the task should behave when interrupted */
|
|
46
|
+
interrupt?: TaskInterruptBehavior;
|
|
47
|
+
/**
|
|
48
|
+
* The task's main generator function. This is called repeatedly until it's done.
|
|
49
|
+
* The function must yield at points where it may be interrupted.
|
|
50
|
+
*
|
|
51
|
+
* At those points, the task can also wait for something to happen:
|
|
52
|
+
* - Either a Promise, in which case it must yield a function that returns that Promise
|
|
53
|
+
* - Or another task, in which case it must yield a TaskBuilder object or a function that returns one
|
|
54
|
+
*
|
|
55
|
+
* Yielded Promises should not spawn new tasks. If they do, the spawned tasks MUST have a higher priority than the parent task.
|
|
56
|
+
*/
|
|
57
|
+
task: () => AsyncGenerator<(() => Promise<TInner> | TaskBuilder<TReturn, TaskTag, TInner>) | (() => TaskBuilder<TReturn, TaskTag, TInner>) | TaskBuilder<TReturn, TaskTag, TInner> | undefined, TReturn, TInner>;
|
|
58
|
+
/** A cleanup function that gets called when the task is dropped */
|
|
59
|
+
cleanup?: () => Promise<void>;
|
|
60
|
+
}
|
|
61
|
+
export type TaskReturnType<T extends TaskBuilder<unknown>> = T extends TaskBuilder<infer R> ? R : never;
|
|
62
|
+
/**
|
|
63
|
+
* The priority of a task.
|
|
64
|
+
*
|
|
65
|
+
* Higher priority tasks are executed first and interrupt lower priority tasks.
|
|
66
|
+
* The recommended priority for application-initiated communication is `Normal`.
|
|
67
|
+
* `Low` and `Lower` are recommended for internal long-running tasks that should not interfere with user-initiated tasks.
|
|
68
|
+
* `Idle` is recommended for tasks that should only run when no other tasks are pending.
|
|
69
|
+
*/
|
|
70
|
+
export declare enum TaskPriority {
|
|
71
|
+
Highest = 0,
|
|
72
|
+
High = 1,
|
|
73
|
+
Normal = 2,
|
|
74
|
+
Low = 3,
|
|
75
|
+
Lower = 4,
|
|
76
|
+
Idle = 5
|
|
77
|
+
}
|
|
78
|
+
export declare enum TaskState {
|
|
79
|
+
/** The task has not been created yet */
|
|
80
|
+
None = 0,
|
|
81
|
+
/** The task is being executed */
|
|
82
|
+
Active = 1,
|
|
83
|
+
/** The task is waiting for a Promise to resolve */
|
|
84
|
+
AwaitingPromise = 2,
|
|
85
|
+
/** The task is waiting for another task to finish */
|
|
86
|
+
AwaitingTask = 3,
|
|
87
|
+
/** The task is finished */
|
|
88
|
+
Done = 4
|
|
89
|
+
}
|
|
90
|
+
export declare enum TaskInterruptBehavior {
|
|
91
|
+
/** The task may not be interrupted */
|
|
92
|
+
Forbidden = 0,
|
|
93
|
+
/** The task will be resumed after being interrupted (default) */
|
|
94
|
+
Resume = 1,
|
|
95
|
+
/** The task needs to be restarted after being interrupted */
|
|
96
|
+
Restart = 2
|
|
97
|
+
}
|
|
98
|
+
export type TaskStepResult<T, TaskTag extends {
|
|
99
|
+
id: string;
|
|
100
|
+
} = {
|
|
101
|
+
id: string;
|
|
102
|
+
}> = {
|
|
103
|
+
newState: TaskState.Done;
|
|
104
|
+
result: T;
|
|
105
|
+
} | {
|
|
106
|
+
newState: TaskState.Active;
|
|
107
|
+
} | {
|
|
108
|
+
newState: TaskState.AwaitingPromise;
|
|
109
|
+
promise: Promise<unknown>;
|
|
110
|
+
} | {
|
|
111
|
+
newState: TaskState.AwaitingTask;
|
|
112
|
+
task: Task<unknown, TaskTag>;
|
|
113
|
+
};
|
|
114
|
+
export declare class TaskScheduler<TaskTag extends {
|
|
115
|
+
id: string;
|
|
116
|
+
} = {
|
|
117
|
+
id: string;
|
|
118
|
+
}, TError extends Error = Error> {
|
|
119
|
+
private defaultErrorFactory;
|
|
120
|
+
private verbose;
|
|
121
|
+
constructor(defaultErrorFactory?: () => TError, verbose?: boolean);
|
|
122
|
+
private _tasks;
|
|
123
|
+
private _currentTask;
|
|
124
|
+
private _idGenerator;
|
|
125
|
+
private _continueSignal;
|
|
126
|
+
private _stopSignal;
|
|
127
|
+
private _stopPromise;
|
|
128
|
+
queueTask<T>(builder: TaskBuilder<T, TaskTag>): Promise<T>;
|
|
129
|
+
/** Removes/stops tasks matching the given predicate. Returns `true` when a task was removed, `false` otherwise. */
|
|
130
|
+
removeTasks(predicate: (task: Task<unknown, TaskTag>) => boolean, reason?: TError): Promise<boolean>;
|
|
131
|
+
findTask<T = unknown>(predicate: (task: Task<T, TaskTag>) => boolean): Promise<T> | undefined;
|
|
132
|
+
/** Creates a task that can be executed */
|
|
133
|
+
private createTask;
|
|
134
|
+
start(): void;
|
|
135
|
+
private run;
|
|
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O,CAAC,YAAY,CAAoC;IAEjD,SAAS,CAAC,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAWjE,mHAAmH;IACtG,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;IAoEZ,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;IAMzB,0CAA0C;IAC1C,OAAO,CAAC,UAAU;IAiIX,KAAK,IAAI,IAAI;YAWN,GAAG;IAsIJ,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAOlC"}
|
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
import { createDeferredPromise, } from "alcalzone-shared/deferred-promise";
|
|
2
|
+
import { SortedList } from "alcalzone-shared/sorted-list";
|
|
3
|
+
import { createWrappingCounter } from "./wrappingCounter.js";
|
|
4
|
+
import { evalOrStatic, highResTimestamp, noop } from "./utils.js";
|
|
5
|
+
function getTaskName(task) {
|
|
6
|
+
return `${task.name ?? (task.tag && JSON.stringify(task.tag)) ?? "unnamed"} (ID ${task.id})`;
|
|
7
|
+
}
|
|
8
|
+
function isTaskBuilder(obj) {
|
|
9
|
+
return (typeof obj === "object" &&
|
|
10
|
+
typeof obj.task === "function" &&
|
|
11
|
+
typeof obj.priority === "number");
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The priority of a task.
|
|
15
|
+
*
|
|
16
|
+
* Higher priority tasks are executed first and interrupt lower priority tasks.
|
|
17
|
+
* The recommended priority for application-initiated communication is `Normal`.
|
|
18
|
+
* `Low` and `Lower` are recommended for internal long-running tasks that should not interfere with user-initiated tasks.
|
|
19
|
+
* `Idle` is recommended for tasks that should only run when no other tasks are pending.
|
|
20
|
+
*/
|
|
21
|
+
export var TaskPriority;
|
|
22
|
+
(function (TaskPriority) {
|
|
23
|
+
TaskPriority[TaskPriority["Highest"] = 0] = "Highest";
|
|
24
|
+
TaskPriority[TaskPriority["High"] = 1] = "High";
|
|
25
|
+
TaskPriority[TaskPriority["Normal"] = 2] = "Normal";
|
|
26
|
+
TaskPriority[TaskPriority["Low"] = 3] = "Low";
|
|
27
|
+
TaskPriority[TaskPriority["Lower"] = 4] = "Lower";
|
|
28
|
+
TaskPriority[TaskPriority["Idle"] = 5] = "Idle";
|
|
29
|
+
})(TaskPriority || (TaskPriority = {}));
|
|
30
|
+
export var TaskState;
|
|
31
|
+
(function (TaskState) {
|
|
32
|
+
/** The task has not been created yet */
|
|
33
|
+
TaskState[TaskState["None"] = 0] = "None";
|
|
34
|
+
/** The task is being executed */
|
|
35
|
+
TaskState[TaskState["Active"] = 1] = "Active";
|
|
36
|
+
/** The task is waiting for a Promise to resolve */
|
|
37
|
+
TaskState[TaskState["AwaitingPromise"] = 2] = "AwaitingPromise";
|
|
38
|
+
/** The task is waiting for another task to finish */
|
|
39
|
+
TaskState[TaskState["AwaitingTask"] = 3] = "AwaitingTask";
|
|
40
|
+
/** The task is finished */
|
|
41
|
+
TaskState[TaskState["Done"] = 4] = "Done";
|
|
42
|
+
})(TaskState || (TaskState = {}));
|
|
43
|
+
export var TaskInterruptBehavior;
|
|
44
|
+
(function (TaskInterruptBehavior) {
|
|
45
|
+
/** The task may not be interrupted */
|
|
46
|
+
TaskInterruptBehavior[TaskInterruptBehavior["Forbidden"] = 0] = "Forbidden";
|
|
47
|
+
/** The task will be resumed after being interrupted (default) */
|
|
48
|
+
TaskInterruptBehavior[TaskInterruptBehavior["Resume"] = 1] = "Resume";
|
|
49
|
+
/** The task needs to be restarted after being interrupted */
|
|
50
|
+
TaskInterruptBehavior[TaskInterruptBehavior["Restart"] = 2] = "Restart";
|
|
51
|
+
})(TaskInterruptBehavior || (TaskInterruptBehavior = {}));
|
|
52
|
+
function compareTasks(a, b) {
|
|
53
|
+
// Sort by priority first. Higher priority goes to the end of the list
|
|
54
|
+
if (a.priority < b.priority)
|
|
55
|
+
return 1;
|
|
56
|
+
if (a.priority > b.priority)
|
|
57
|
+
return -1;
|
|
58
|
+
// Deprioritize waiting tasks
|
|
59
|
+
const aWaiting = a.state === TaskState.AwaitingPromise ||
|
|
60
|
+
a.state === TaskState.AwaitingTask;
|
|
61
|
+
const bWaiting = b.state === TaskState.AwaitingPromise ||
|
|
62
|
+
b.state === TaskState.AwaitingTask;
|
|
63
|
+
if (!aWaiting && bWaiting)
|
|
64
|
+
return 1;
|
|
65
|
+
if (aWaiting && !bWaiting)
|
|
66
|
+
return -1;
|
|
67
|
+
// Sort equal priority by timestamp. Newer tasks go to the end of the list
|
|
68
|
+
if (a.timestamp < b.timestamp)
|
|
69
|
+
return 1;
|
|
70
|
+
if (a.timestamp > b.timestamp)
|
|
71
|
+
return -1;
|
|
72
|
+
// If all else fails, sort by ID
|
|
73
|
+
return Math.sign(b.id - a.id);
|
|
74
|
+
}
|
|
75
|
+
export class TaskScheduler {
|
|
76
|
+
defaultErrorFactory;
|
|
77
|
+
verbose;
|
|
78
|
+
constructor(defaultErrorFactory = () => new Error("Task was removed"), verbose = false) {
|
|
79
|
+
this.defaultErrorFactory = defaultErrorFactory;
|
|
80
|
+
this.verbose = verbose;
|
|
81
|
+
}
|
|
82
|
+
_tasks = new SortedList(undefined, compareTasks);
|
|
83
|
+
_currentTask;
|
|
84
|
+
_idGenerator = createWrappingCounter(0xff_ff_ff);
|
|
85
|
+
_continueSignal;
|
|
86
|
+
_stopSignal;
|
|
87
|
+
_stopPromise;
|
|
88
|
+
queueTask(builder) {
|
|
89
|
+
const task = this.createTask(builder);
|
|
90
|
+
this._tasks.add(task);
|
|
91
|
+
if (this.verbose) {
|
|
92
|
+
console.log(`Task queued: ${getTaskName(task)}`);
|
|
93
|
+
}
|
|
94
|
+
if (this._continueSignal)
|
|
95
|
+
this._continueSignal.resolve();
|
|
96
|
+
return task.promise;
|
|
97
|
+
}
|
|
98
|
+
/** Removes/stops tasks matching the given predicate. Returns `true` when a task was removed, `false` otherwise. */
|
|
99
|
+
async removeTasks(predicate, reason) {
|
|
100
|
+
// Collect tasks that should be removed, but in reverse order,
|
|
101
|
+
// so that we handle the current task last.
|
|
102
|
+
const tasksToRemove = [];
|
|
103
|
+
let removeCurrentTask = false;
|
|
104
|
+
for (const task of this._tasks) {
|
|
105
|
+
if (predicate(task)) {
|
|
106
|
+
if (task === this._currentTask) {
|
|
107
|
+
removeCurrentTask = true;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
tasksToRemove.push(task);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
reason ??= this.defaultErrorFactory();
|
|
115
|
+
for (const task of tasksToRemove) {
|
|
116
|
+
if (this.verbose) {
|
|
117
|
+
console.log(`Removing task: ${getTaskName(task)}`);
|
|
118
|
+
}
|
|
119
|
+
this._tasks.remove(task);
|
|
120
|
+
if (task.state === TaskState.Active ||
|
|
121
|
+
task.state === TaskState.AwaitingPromise ||
|
|
122
|
+
task.state === TaskState.AwaitingTask) {
|
|
123
|
+
// The task is running, clean it up
|
|
124
|
+
await task.reset().catch(noop);
|
|
125
|
+
}
|
|
126
|
+
task.reject(reason);
|
|
127
|
+
// Re-add the parent task to the list if there is one
|
|
128
|
+
if (task.parent) {
|
|
129
|
+
if (this.verbose) {
|
|
130
|
+
console.log(`Restoring parent task: ${getTaskName(task.parent)}`);
|
|
131
|
+
}
|
|
132
|
+
this._tasks.add(task.parent);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (removeCurrentTask && this._currentTask) {
|
|
136
|
+
if (this.verbose) {
|
|
137
|
+
console.log(`Removing task: ${getTaskName(this._currentTask)}`);
|
|
138
|
+
}
|
|
139
|
+
this._tasks.remove(this._currentTask);
|
|
140
|
+
await this._currentTask.reset().catch(noop);
|
|
141
|
+
this._currentTask.reject(reason);
|
|
142
|
+
// Re-add the parent task to the list if there is one
|
|
143
|
+
if (this._currentTask.parent) {
|
|
144
|
+
if (this.verbose) {
|
|
145
|
+
console.log(`Restoring parent task: ${getTaskName(this._currentTask.parent)}`);
|
|
146
|
+
}
|
|
147
|
+
this._tasks.add(this._currentTask.parent);
|
|
148
|
+
}
|
|
149
|
+
this._currentTask = undefined;
|
|
150
|
+
}
|
|
151
|
+
if (this._continueSignal)
|
|
152
|
+
this._continueSignal.resolve();
|
|
153
|
+
return tasksToRemove.length > 0 || removeCurrentTask;
|
|
154
|
+
}
|
|
155
|
+
findTask(predicate) {
|
|
156
|
+
return this._tasks.find((t) => predicate(t))?.promise;
|
|
157
|
+
}
|
|
158
|
+
/** Creates a task that can be executed */
|
|
159
|
+
createTask(builder, parent) {
|
|
160
|
+
let state = TaskState.None;
|
|
161
|
+
let generator;
|
|
162
|
+
let waitForPromise;
|
|
163
|
+
const promise = createDeferredPromise();
|
|
164
|
+
let prevResult;
|
|
165
|
+
let waitError;
|
|
166
|
+
const self = this;
|
|
167
|
+
return {
|
|
168
|
+
id: this._idGenerator(),
|
|
169
|
+
timestamp: highResTimestamp(),
|
|
170
|
+
builder,
|
|
171
|
+
parent,
|
|
172
|
+
name: builder.name,
|
|
173
|
+
tag: builder.tag,
|
|
174
|
+
priority: builder.priority,
|
|
175
|
+
interrupt: builder.interrupt ?? TaskInterruptBehavior.Resume,
|
|
176
|
+
promise,
|
|
177
|
+
async step() {
|
|
178
|
+
// Do not proceed while still waiting for a Promise to resolve
|
|
179
|
+
if (state === TaskState.AwaitingPromise && waitForPromise) {
|
|
180
|
+
return {
|
|
181
|
+
newState: state,
|
|
182
|
+
promise: waitForPromise,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
else if (state === TaskState.AwaitingTask) {
|
|
186
|
+
throw new Error("Cannot step through a task that is waiting for another task");
|
|
187
|
+
}
|
|
188
|
+
generator ??= builder.task();
|
|
189
|
+
state = TaskState.Active;
|
|
190
|
+
const { value, done } = waitError
|
|
191
|
+
? await generator.throw(waitError)
|
|
192
|
+
: await generator.next(prevResult);
|
|
193
|
+
prevResult = undefined;
|
|
194
|
+
waitError = undefined;
|
|
195
|
+
if (done) {
|
|
196
|
+
state = TaskState.Done;
|
|
197
|
+
return {
|
|
198
|
+
newState: state,
|
|
199
|
+
result: value,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
else if (value != undefined) {
|
|
203
|
+
const waitFor = evalOrStatic(value);
|
|
204
|
+
if (waitFor instanceof Promise) {
|
|
205
|
+
state = TaskState.AwaitingPromise;
|
|
206
|
+
waitForPromise = waitFor
|
|
207
|
+
.then((result) => {
|
|
208
|
+
prevResult = result;
|
|
209
|
+
})
|
|
210
|
+
.catch((e) => {
|
|
211
|
+
waitError = e;
|
|
212
|
+
})
|
|
213
|
+
.finally(() => {
|
|
214
|
+
waitForPromise = undefined;
|
|
215
|
+
if (state === TaskState.AwaitingPromise) {
|
|
216
|
+
state = TaskState.Active;
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
return {
|
|
220
|
+
newState: state,
|
|
221
|
+
promise: waitForPromise,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
else if (isTaskBuilder(waitFor)) {
|
|
225
|
+
if (waitFor.priority > builder.priority) {
|
|
226
|
+
throw new Error("Tasks cannot yield to tasks with lower priority than their own");
|
|
227
|
+
}
|
|
228
|
+
// Create a sub-task with a reference to this task
|
|
229
|
+
state = TaskState.AwaitingTask;
|
|
230
|
+
const subTask = self.createTask(waitFor, this);
|
|
231
|
+
subTask.promise
|
|
232
|
+
.then((result) => {
|
|
233
|
+
prevResult = result;
|
|
234
|
+
})
|
|
235
|
+
.catch((e) => {
|
|
236
|
+
waitError = e;
|
|
237
|
+
})
|
|
238
|
+
.finally(() => {
|
|
239
|
+
if (state === TaskState.AwaitingTask) {
|
|
240
|
+
state = TaskState.Active;
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
return {
|
|
244
|
+
newState: state,
|
|
245
|
+
task: subTask,
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
throw new Error("Invalid value yielded by task");
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
return { newState: state };
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
async reset() {
|
|
257
|
+
if (state === TaskState.None)
|
|
258
|
+
return;
|
|
259
|
+
state = TaskState.None;
|
|
260
|
+
waitForPromise = undefined;
|
|
261
|
+
generator = undefined;
|
|
262
|
+
await builder.cleanup?.();
|
|
263
|
+
},
|
|
264
|
+
resolve(result) {
|
|
265
|
+
promise.resolve(result);
|
|
266
|
+
},
|
|
267
|
+
reject(error) {
|
|
268
|
+
promise.reject(error);
|
|
269
|
+
},
|
|
270
|
+
get state() {
|
|
271
|
+
return state;
|
|
272
|
+
},
|
|
273
|
+
get generator() {
|
|
274
|
+
return generator;
|
|
275
|
+
},
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
start() {
|
|
279
|
+
this._stopSignal = createDeferredPromise();
|
|
280
|
+
setImmediate(async () => {
|
|
281
|
+
try {
|
|
282
|
+
await this.run();
|
|
283
|
+
}
|
|
284
|
+
catch (e) {
|
|
285
|
+
console.error("Task runner crashed", e);
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
async run() {
|
|
290
|
+
while (true) {
|
|
291
|
+
let waitFor;
|
|
292
|
+
if (this._tasks.length > 0) {
|
|
293
|
+
const firstTask = this._tasks.peekStart();
|
|
294
|
+
if (!this._currentTask) {
|
|
295
|
+
// We're not currently executing a task, start executing the first one
|
|
296
|
+
this._currentTask = firstTask;
|
|
297
|
+
}
|
|
298
|
+
else if (this._currentTask !== firstTask &&
|
|
299
|
+
this._currentTask.interrupt !==
|
|
300
|
+
TaskInterruptBehavior.Forbidden) {
|
|
301
|
+
// We are executing an interruptible task, and a new task with a higher priority was added
|
|
302
|
+
if (this._currentTask.interrupt ===
|
|
303
|
+
TaskInterruptBehavior.Restart) {
|
|
304
|
+
// The current task needs to be restarted after being interrupted, so reset it
|
|
305
|
+
await this._currentTask.reset();
|
|
306
|
+
}
|
|
307
|
+
// switch to the new task
|
|
308
|
+
this._currentTask = firstTask;
|
|
309
|
+
}
|
|
310
|
+
if (this.verbose) {
|
|
311
|
+
console.log(`Stepping through task: ${getTaskName(this._currentTask)}`);
|
|
312
|
+
}
|
|
313
|
+
const cleanupCurrentTask = async () => {
|
|
314
|
+
if (this._currentTask) {
|
|
315
|
+
this._tasks.remove(this._currentTask);
|
|
316
|
+
await this._currentTask.reset();
|
|
317
|
+
// Re-add the parent task to the list if there is one
|
|
318
|
+
if (this._currentTask.parent) {
|
|
319
|
+
if (this.verbose) {
|
|
320
|
+
console.log(`Restoring parent task: ${getTaskName(this._currentTask.parent)}`);
|
|
321
|
+
}
|
|
322
|
+
this._tasks.add(this._currentTask.parent);
|
|
323
|
+
}
|
|
324
|
+
this._currentTask = undefined;
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
// Execute the current task one step further
|
|
328
|
+
waitFor = undefined;
|
|
329
|
+
let stepResult;
|
|
330
|
+
try {
|
|
331
|
+
stepResult = await this._currentTask.step();
|
|
332
|
+
}
|
|
333
|
+
catch (e) {
|
|
334
|
+
if (this.verbose) {
|
|
335
|
+
console.error(`- Task threw an error:`, e);
|
|
336
|
+
}
|
|
337
|
+
// The task threw an error, expose the result and clean up.
|
|
338
|
+
this._currentTask.reject(e);
|
|
339
|
+
await cleanupCurrentTask();
|
|
340
|
+
// Then continue with the next iteration
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
if (stepResult.newState === TaskState.Done) {
|
|
344
|
+
if (this.verbose) {
|
|
345
|
+
console.log(`- Task finished`);
|
|
346
|
+
}
|
|
347
|
+
// The task is done, clean up
|
|
348
|
+
this._currentTask.resolve(stepResult.result);
|
|
349
|
+
await cleanupCurrentTask();
|
|
350
|
+
// Then continue with the next iteration
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
else if (stepResult.newState === TaskState.AwaitingPromise) {
|
|
354
|
+
// The task is waiting for something
|
|
355
|
+
if (this.verbose) {
|
|
356
|
+
console.log(`- Task waiting`);
|
|
357
|
+
}
|
|
358
|
+
// If the task may be interrupted, check if there are other same-priority tasks that should be executed instead
|
|
359
|
+
if (this._currentTask.interrupt !==
|
|
360
|
+
TaskInterruptBehavior.Forbidden) {
|
|
361
|
+
// Re-queue the task, so the queue gets reordered
|
|
362
|
+
this._tasks.remove(this._currentTask);
|
|
363
|
+
this._tasks.add(this._currentTask);
|
|
364
|
+
if (this._tasks.peekStart() !== this._currentTask) {
|
|
365
|
+
if (this.verbose) {
|
|
366
|
+
console.log(`-- Continuing with another task`);
|
|
367
|
+
}
|
|
368
|
+
// The task is no longer the first in the queue. Switch to the other one
|
|
369
|
+
continue;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
// Otherwise, we got nothing to do right now than to wait
|
|
373
|
+
waitFor = stepResult.promise;
|
|
374
|
+
}
|
|
375
|
+
else if (stepResult.newState === TaskState.AwaitingTask) {
|
|
376
|
+
// The task spawned a sub-task. Replace it with the sub-task and continue executing
|
|
377
|
+
if (this.verbose) {
|
|
378
|
+
console.log(`- Task spawned a sub-task`);
|
|
379
|
+
}
|
|
380
|
+
this._tasks.add(stepResult.task);
|
|
381
|
+
this._tasks.remove(this._currentTask);
|
|
382
|
+
// Continue with the next iteration
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
else {
|
|
386
|
+
// The current task is not done, continue with the next iteration
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
// Task queue empty. Wait for either a new task or the stop signal,
|
|
391
|
+
// or the current task to finish waiting
|
|
392
|
+
this._continueSignal = createDeferredPromise();
|
|
393
|
+
const nextAction = await Promise.race([
|
|
394
|
+
this._continueSignal.then(() => "continue"),
|
|
395
|
+
this._stopSignal.then(() => "stop"),
|
|
396
|
+
waitFor?.then(() => "continue"),
|
|
397
|
+
].filter((p) => p !== undefined));
|
|
398
|
+
this._continueSignal = undefined;
|
|
399
|
+
if (nextAction === "stop")
|
|
400
|
+
break;
|
|
401
|
+
}
|
|
402
|
+
this._stopPromise.resolve();
|
|
403
|
+
}
|
|
404
|
+
async stop() {
|
|
405
|
+
if (!this._stopSignal)
|
|
406
|
+
return;
|
|
407
|
+
// Signal to the task runner that it should stop
|
|
408
|
+
this._stopPromise = createDeferredPromise();
|
|
409
|
+
this._stopSignal.resolve();
|
|
410
|
+
await this._stopPromise;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
//# sourceMappingURL=Task.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Task.js","sourceRoot":"","sources":["../../src/Task.ts"],"names":[],"mappings":"AACA,OAAO,EAEN,qBAAqB,GACrB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAsClE,SAAS,WAAW,CAAC,IAAmB;IACvC,OAAO,GACN,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,SACxD,QAAQ,IAAI,CAAC,EAAE,GAAG,CAAC;AACpB,CAAC;AAyCD,SAAS,aAAa,CAAI,GAAQ;IACjC,OAAO,CACN,OAAO,GAAG,KAAK,QAAQ;QACvB,OAAO,GAAG,CAAC,IAAI,KAAK,UAAU;QAC9B,OAAO,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAChC,CAAC;AACH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ACV,CAAC;YACF,CAAC;YAED,mEAAmE;YACnE,wCAAwC;YACxC,IAAI,CAAC,eAAe,GAAG,qBAAqB,EAAE,CAAC;YAC/C,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,IAAI,CACpC;gBACC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,UAAmB,CAAC;gBACpD,IAAI,CAAC,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,IAAI,EACJ,WAAW,EACX,qBAAqB,EACrB,YAAY,EACZ,cAAc,EACd,aAAa,EACb,SAAS,EACT,cAAc,GACd,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,qBAAqB,EACrB,YAAY,EAEZ,aAAa,EACb,SAAS,GAET,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Returns a timestamp with nano-second precision */
|
|
2
|
+
export declare function highResTimestamp(): number;
|
|
3
|
+
/** Does nothing. Can be used for empty `.catch(...)` calls. */
|
|
4
|
+
export declare function noop(): void;
|
|
5
|
+
export type FnOrStatic<TArgs extends any[], TReturn> = ((...args: TArgs) => TReturn) | TReturn;
|
|
6
|
+
export type ReturnTypeOrStatic<T> = T extends (...args: any[]) => infer R ? R : T;
|
|
7
|
+
export declare function evalOrStatic<T>(fnOrConst: T, ...args: any[]): ReturnTypeOrStatic<T>;
|
|
8
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,wBAAgB,gBAAgB,IAAI,MAAM,CASzC;AAED,+DAA+D;AAC/D,wBAAgB,IAAI,IAAI,IAAI,CAE3B;AAED,MAAM,MAAM,UAAU,CAAC,KAAK,SAAS,GAAG,EAAE,EAAE,OAAO,IAChD,CAAC,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,CAAC,GAC7B,OAAO,CAAC;AAEX,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAAC,GAAG,CAAC,GAC1E,CAAC,CAAC;AAEL,wBAAgB,YAAY,CAAC,CAAC,EAC7B,SAAS,EAAE,CAAC,EACZ,GAAG,IAAI,EAAE,GAAG,EAAE,GACZ,kBAAkB,CAAC,CAAC,CAAC,CAGvB"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Returns a timestamp with nano-second precision */
|
|
2
|
+
export function highResTimestamp() {
|
|
3
|
+
if (typeof process !== "undefined") {
|
|
4
|
+
const [s, ns] = process.hrtime();
|
|
5
|
+
return s * 1e9 + ns;
|
|
6
|
+
}
|
|
7
|
+
else if (performance != undefined) {
|
|
8
|
+
return performance.now() * 1e6;
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
throw new Error("No high-resolution timer available");
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/** Does nothing. Can be used for empty `.catch(...)` calls. */
|
|
15
|
+
export function noop() {
|
|
16
|
+
// intentionally empty
|
|
17
|
+
}
|
|
18
|
+
export function evalOrStatic(fnOrConst, ...args) {
|
|
19
|
+
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/61337
|
|
20
|
+
return typeof fnOrConst === "function" ? fnOrConst(...args) : fnOrConst;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,MAAM,UAAU,gBAAgB;IAC/B,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE,CAAC;QACpC,MAAM,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;QACjC,OAAO,CAAC,GAAG,GAAG,GAAG,EAAE,CAAC;IACrB,CAAC;SAAM,IAAI,WAAW,IAAI,SAAS,EAAE,CAAC;QACrC,OAAO,WAAW,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC;IAChC,CAAC;SAAM,CAAC;QACP,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IACvD,CAAC;AACF,CAAC;AAED,+DAA+D;AAC/D,MAAM,UAAU,IAAI;IACnB,sBAAsB;AACvB,CAAC;AASD,MAAM,UAAU,YAAY,CAC3B,SAAY,EACZ,GAAG,IAAW;IAEd,wEAAwE;IACxE,OAAO,OAAO,SAAS,KAAK,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACzE,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a counter that starts at 1 and wraps after surpassing `maxValue`.
|
|
3
|
+
* @param maxValue The maximum value that the counter can reach. Must a number where all bits are set to 1.
|
|
4
|
+
* @param randomSeed Whether the initial value should be randomized. Default: `false`.
|
|
5
|
+
*/
|
|
6
|
+
export declare function createWrappingCounter(maxValue: number, randomSeed?: boolean): () => number;
|
|
7
|
+
//# sourceMappingURL=wrappingCounter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wrappingCounter.d.ts","sourceRoot":"","sources":["../../src/wrappingCounter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,qBAAqB,CACpC,QAAQ,EAAE,MAAM,EAChB,UAAU,GAAE,OAAe,GACzB,MAAM,MAAM,CAOd"}
|