ngx-task 0.1.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 +120 -0
- package/lib/adapters/observable-adapter.d.ts +20 -0
- package/lib/adapters/observable-adapter.d.ts.map +1 -0
- package/lib/adapters/observable-adapter.js +106 -0
- package/lib/adapters/observable-adapter.js.map +1 -0
- package/lib/adapters/promise-adapter.d.ts +12 -0
- package/lib/adapters/promise-adapter.d.ts.map +1 -0
- package/lib/adapters/promise-adapter.js +50 -0
- package/lib/adapters/promise-adapter.js.map +1 -0
- package/lib/angular/create-task.d.ts +3 -0
- package/lib/angular/create-task.d.ts.map +1 -0
- package/lib/angular/create-task.js +312 -0
- package/lib/angular/create-task.js.map +1 -0
- package/lib/angular/task.interface.d.ts +55 -0
- package/lib/angular/task.interface.d.ts.map +1 -0
- package/lib/angular/task.interface.js +3 -0
- package/lib/angular/task.interface.js.map +1 -0
- package/lib/core/execution-state-machine.d.ts +53 -0
- package/lib/core/execution-state-machine.d.ts.map +1 -0
- package/lib/core/execution-state-machine.js +217 -0
- package/lib/core/execution-state-machine.js.map +1 -0
- package/lib/core/outcome.d.ts +19 -0
- package/lib/core/outcome.d.ts.map +1 -0
- package/lib/core/outcome.js +3 -0
- package/lib/core/outcome.js.map +1 -0
- package/lib/core/task-context.d.ts +10 -0
- package/lib/core/task-context.d.ts.map +1 -0
- package/lib/core/task-context.js +3 -0
- package/lib/core/task-context.js.map +1 -0
- package/lib/core/types.d.ts +21 -0
- package/lib/core/types.d.ts.map +1 -0
- package/lib/core/types.js +3 -0
- package/lib/core/types.js.map +1 -0
- package/lib/directives/public-api.d.ts +4 -0
- package/lib/directives/public-api.d.ts.map +1 -0
- package/lib/directives/public-api.js +20 -0
- package/lib/directives/public-api.js.map +1 -0
- package/lib/directives/task-busy.directive.d.ts +8 -0
- package/lib/directives/task-busy.directive.d.ts.map +1 -0
- package/lib/directives/task-busy.directive.js +35 -0
- package/lib/directives/task-busy.directive.js.map +1 -0
- package/lib/directives/task-disable-while-pending.directive.d.ts +14 -0
- package/lib/directives/task-disable-while-pending.directive.d.ts.map +1 -0
- package/lib/directives/task-disable-while-pending.directive.js +54 -0
- package/lib/directives/task-disable-while-pending.directive.js.map +1 -0
- package/lib/directives/task-trigger.directive.d.ts +7 -0
- package/lib/directives/task-trigger.directive.d.ts.map +1 -0
- package/lib/directives/task-trigger.directive.js +31 -0
- package/lib/directives/task-trigger.directive.js.map +1 -0
- package/lib/schedulers/drop-scheduler.d.ts +13 -0
- package/lib/schedulers/drop-scheduler.d.ts.map +1 -0
- package/lib/schedulers/drop-scheduler.js +50 -0
- package/lib/schedulers/drop-scheduler.js.map +1 -0
- package/lib/schedulers/enqueue-scheduler.d.ts +23 -0
- package/lib/schedulers/enqueue-scheduler.d.ts.map +1 -0
- package/lib/schedulers/enqueue-scheduler.js +89 -0
- package/lib/schedulers/enqueue-scheduler.js.map +1 -0
- package/lib/schedulers/latest-scheduler.d.ts +15 -0
- package/lib/schedulers/latest-scheduler.d.ts.map +1 -0
- package/lib/schedulers/latest-scheduler.js +72 -0
- package/lib/schedulers/latest-scheduler.js.map +1 -0
- package/lib/schedulers/parallel-scheduler.d.ts +25 -0
- package/lib/schedulers/parallel-scheduler.d.ts.map +1 -0
- package/lib/schedulers/parallel-scheduler.js +93 -0
- package/lib/schedulers/parallel-scheduler.js.map +1 -0
- package/lib/schedulers/restart-scheduler.d.ts +13 -0
- package/lib/schedulers/restart-scheduler.d.ts.map +1 -0
- package/lib/schedulers/restart-scheduler.js +51 -0
- package/lib/schedulers/restart-scheduler.js.map +1 -0
- package/lib/schedulers/scheduler.interface.d.ts +11 -0
- package/lib/schedulers/scheduler.interface.d.ts.map +1 -0
- package/lib/schedulers/scheduler.interface.js +3 -0
- package/lib/schedulers/scheduler.interface.js.map +1 -0
- package/lib/testing/deferred.d.ts +8 -0
- package/lib/testing/deferred.d.ts.map +1 -0
- package/lib/testing/deferred.js +27 -0
- package/lib/testing/deferred.js.map +1 -0
- package/lib/testing/harness.d.ts +25 -0
- package/lib/testing/harness.d.ts.map +1 -0
- package/lib/testing/harness.js +66 -0
- package/lib/testing/harness.js.map +1 -0
- package/lib/testing/public-api.d.ts +4 -0
- package/lib/testing/public-api.d.ts.map +1 -0
- package/lib/testing/public-api.js +20 -0
- package/lib/testing/public-api.js.map +1 -0
- package/lib/testing/test-clock.d.ts +7 -0
- package/lib/testing/test-clock.d.ts.map +1 -0
- package/lib/testing/test-clock.js +20 -0
- package/lib/testing/test-clock.js.map +1 -0
- package/package.json +51 -0
- package/public-api.d.ts +17 -0
- package/public-api.d.ts.map +1 -0
- package/public-api.js +33 -0
- package/public-api.js.map +1 -0
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTask = createTask;
|
|
4
|
+
const core_1 = require("@angular/core");
|
|
5
|
+
const execution_state_machine_js_1 = require("../core/execution-state-machine.js");
|
|
6
|
+
const promise_adapter_js_1 = require("../adapters/promise-adapter.js");
|
|
7
|
+
const observable_adapter_js_1 = require("../adapters/observable-adapter.js");
|
|
8
|
+
const drop_scheduler_js_1 = require("../schedulers/drop-scheduler.js");
|
|
9
|
+
const restart_scheduler_js_1 = require("../schedulers/restart-scheduler.js");
|
|
10
|
+
const enqueue_scheduler_js_1 = require("../schedulers/enqueue-scheduler.js");
|
|
11
|
+
const latest_scheduler_js_1 = require("../schedulers/latest-scheduler.js");
|
|
12
|
+
const parallel_scheduler_js_1 = require("../schedulers/parallel-scheduler.js");
|
|
13
|
+
class TaskExecutionImpl {
|
|
14
|
+
stateMachine;
|
|
15
|
+
id;
|
|
16
|
+
args;
|
|
17
|
+
createdAt;
|
|
18
|
+
statusSig;
|
|
19
|
+
progressSig;
|
|
20
|
+
resultSig;
|
|
21
|
+
errorSig;
|
|
22
|
+
startedAtSig;
|
|
23
|
+
finishedAtSig;
|
|
24
|
+
status;
|
|
25
|
+
progress;
|
|
26
|
+
result;
|
|
27
|
+
error;
|
|
28
|
+
startedAt;
|
|
29
|
+
finishedAt;
|
|
30
|
+
done;
|
|
31
|
+
constructor(stateMachine) {
|
|
32
|
+
this.stateMachine = stateMachine;
|
|
33
|
+
this.id = stateMachine.id;
|
|
34
|
+
this.args = stateMachine.args;
|
|
35
|
+
this.createdAt = stateMachine.createdAt;
|
|
36
|
+
this.done = stateMachine.done;
|
|
37
|
+
this.statusSig = (0, core_1.signal)(stateMachine.status);
|
|
38
|
+
this.progressSig = (0, core_1.signal)(stateMachine.progress);
|
|
39
|
+
this.resultSig = (0, core_1.signal)(stateMachine.result);
|
|
40
|
+
this.errorSig = (0, core_1.signal)(stateMachine.error);
|
|
41
|
+
this.startedAtSig = (0, core_1.signal)(stateMachine.startedAt);
|
|
42
|
+
this.finishedAtSig = (0, core_1.signal)(stateMachine.finishedAt);
|
|
43
|
+
this.status = this.statusSig.asReadonly();
|
|
44
|
+
this.progress = this.progressSig.asReadonly();
|
|
45
|
+
this.result = this.resultSig.asReadonly();
|
|
46
|
+
this.error = this.errorSig.asReadonly();
|
|
47
|
+
this.startedAt = this.startedAtSig.asReadonly();
|
|
48
|
+
this.finishedAt = this.finishedAtSig.asReadonly();
|
|
49
|
+
stateMachine.addListener({
|
|
50
|
+
onStatusChange: (status) => {
|
|
51
|
+
this.statusSig.set(status);
|
|
52
|
+
this.startedAtSig.set(stateMachine.startedAt);
|
|
53
|
+
this.finishedAtSig.set(stateMachine.finishedAt);
|
|
54
|
+
},
|
|
55
|
+
onProgressChange: (p) => this.progressSig.set(p),
|
|
56
|
+
onResultChange: (r) => this.resultSig.set(r),
|
|
57
|
+
onErrorChange: (e) => this.errorSig.set(e),
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
cancel(reason) {
|
|
61
|
+
this.stateMachine.cancel(reason);
|
|
62
|
+
}
|
|
63
|
+
resultOrThrow() {
|
|
64
|
+
return this.stateMachine.resultOrThrow();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
class TaskImpl {
|
|
68
|
+
handler;
|
|
69
|
+
options;
|
|
70
|
+
statusSig = (0, core_1.signal)('idle');
|
|
71
|
+
pendingSig = (0, core_1.signal)(false);
|
|
72
|
+
runningSig = (0, core_1.signal)(false);
|
|
73
|
+
resultSig = (0, core_1.signal)(undefined);
|
|
74
|
+
errorSig = (0, core_1.signal)(undefined);
|
|
75
|
+
progressSig = (0, core_1.signal)(undefined);
|
|
76
|
+
runningCountSig = (0, core_1.signal)(0);
|
|
77
|
+
queuedCountSig = (0, core_1.signal)(0);
|
|
78
|
+
executionCountSig = (0, core_1.signal)(0);
|
|
79
|
+
lastExecutionSig = (0, core_1.signal)(undefined);
|
|
80
|
+
status = this.statusSig.asReadonly();
|
|
81
|
+
pending = this.pendingSig.asReadonly();
|
|
82
|
+
running = this.runningSig.asReadonly();
|
|
83
|
+
result = this.resultSig.asReadonly();
|
|
84
|
+
error = this.errorSig.asReadonly();
|
|
85
|
+
progress = this.progressSig.asReadonly();
|
|
86
|
+
runningCount = this.runningCountSig.asReadonly();
|
|
87
|
+
queuedCount = this.queuedCountSig.asReadonly();
|
|
88
|
+
executionCount = this.executionCountSig.asReadonly();
|
|
89
|
+
lastExecution = this.lastExecutionSig.asReadonly();
|
|
90
|
+
scheduler;
|
|
91
|
+
classifyError;
|
|
92
|
+
lastArgs;
|
|
93
|
+
seq = 0;
|
|
94
|
+
pendingTimer;
|
|
95
|
+
pendingActiveTime;
|
|
96
|
+
constructor(handler, options) {
|
|
97
|
+
this.handler = handler;
|
|
98
|
+
this.options = options;
|
|
99
|
+
this.classifyError = options?.classifyError ?? promise_adapter_js_1.defaultClassifyError;
|
|
100
|
+
this.scheduler = this.initScheduler(options);
|
|
101
|
+
this.initDestroyRef(options);
|
|
102
|
+
}
|
|
103
|
+
run(args) {
|
|
104
|
+
this.seq++;
|
|
105
|
+
this.lastArgs = args;
|
|
106
|
+
const executionId = `exec-${this.seq}`;
|
|
107
|
+
const stateMachine = new execution_state_machine_js_1.ExecutionStateMachine(executionId, args, this.seq);
|
|
108
|
+
const taskExecution = new TaskExecutionImpl(stateMachine);
|
|
109
|
+
this.executionCountSig.update(c => c + 1);
|
|
110
|
+
this.lastExecutionSig.set(taskExecution);
|
|
111
|
+
// Timeout logic setup
|
|
112
|
+
const timeoutOpt = this.options?.timeout;
|
|
113
|
+
const timeoutMs = typeof timeoutOpt === 'number' ? timeoutOpt : timeoutOpt?.milliseconds;
|
|
114
|
+
const timeoutMsg = typeof timeoutOpt === 'object' ? timeoutOpt.message : undefined;
|
|
115
|
+
let timeoutTimer = undefined;
|
|
116
|
+
stateMachine.addListener({
|
|
117
|
+
onStatusChange: (status) => {
|
|
118
|
+
if (status === 'running' && timeoutMs && timeoutMs > 0) {
|
|
119
|
+
timeoutTimer = setTimeout(() => {
|
|
120
|
+
const timeoutError = {
|
|
121
|
+
cause: new Error(timeoutMsg ?? `Task execution ${executionId} timed out after ${timeoutMs}ms`),
|
|
122
|
+
kind: 'timeout',
|
|
123
|
+
message: timeoutMsg ?? `Task execution ${executionId} timed out after ${timeoutMs}ms`,
|
|
124
|
+
retryable: true,
|
|
125
|
+
};
|
|
126
|
+
stateMachine.timeOut(timeoutError);
|
|
127
|
+
}, timeoutMs);
|
|
128
|
+
}
|
|
129
|
+
else if (stateMachine.isSettled && timeoutTimer) {
|
|
130
|
+
clearTimeout(timeoutTimer);
|
|
131
|
+
timeoutTimer = undefined;
|
|
132
|
+
}
|
|
133
|
+
this.syncCountsAndStatus();
|
|
134
|
+
},
|
|
135
|
+
onProgressChange: (p) => this.progressSig.set(p),
|
|
136
|
+
onResultChange: (res) => {
|
|
137
|
+
if (res !== undefined) {
|
|
138
|
+
this.resultSig.set(res);
|
|
139
|
+
this.errorSig.set(undefined);
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
onErrorChange: (err) => {
|
|
143
|
+
if (err !== undefined) {
|
|
144
|
+
this.errorSig.set(err);
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
stateMachine.done.finally(() => {
|
|
149
|
+
if (timeoutTimer) {
|
|
150
|
+
clearTimeout(timeoutTimer);
|
|
151
|
+
timeoutTimer = undefined;
|
|
152
|
+
}
|
|
153
|
+
queueMicrotask(() => this.syncCountsAndStatus());
|
|
154
|
+
});
|
|
155
|
+
this.scheduler.schedule(stateMachine, (exec) => {
|
|
156
|
+
const context = exec.createContext();
|
|
157
|
+
try {
|
|
158
|
+
const handlerResult = this.handler(exec.args, context);
|
|
159
|
+
if ((0, observable_adapter_js_1.isObservable)(handlerResult)) {
|
|
160
|
+
const obs = handlerResult;
|
|
161
|
+
const obsAdapter = new observable_adapter_js_1.ObservableOperationAdapter(() => obs, {
|
|
162
|
+
observableResult: this.options?.observableResult,
|
|
163
|
+
classifyError: this.classifyError,
|
|
164
|
+
});
|
|
165
|
+
obsAdapter.runWithObservable(exec, obs);
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
const promiseAdapter = new promise_adapter_js_1.PromiseOperationAdapter(async () => handlerResult, this.classifyError);
|
|
169
|
+
promiseAdapter.run(exec);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
catch (err) {
|
|
173
|
+
const taskErr = this.classifyError(err);
|
|
174
|
+
exec.fail(taskErr);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
this.syncCountsAndStatus();
|
|
178
|
+
return taskExecution;
|
|
179
|
+
}
|
|
180
|
+
cancel(reason) {
|
|
181
|
+
const last = this.lastExecutionSig();
|
|
182
|
+
last?.cancel(reason);
|
|
183
|
+
}
|
|
184
|
+
cancelAll(reason) {
|
|
185
|
+
this.scheduler.cancelAll(reason);
|
|
186
|
+
this.syncCountsAndStatus();
|
|
187
|
+
}
|
|
188
|
+
reset() {
|
|
189
|
+
this.resultSig.set(undefined);
|
|
190
|
+
this.errorSig.set(undefined);
|
|
191
|
+
this.progressSig.set(undefined);
|
|
192
|
+
this.statusSig.set('idle');
|
|
193
|
+
}
|
|
194
|
+
retryLast() {
|
|
195
|
+
if (this.lastArgs !== undefined) {
|
|
196
|
+
return this.run(this.lastArgs);
|
|
197
|
+
}
|
|
198
|
+
return undefined;
|
|
199
|
+
}
|
|
200
|
+
syncCountsAndStatus() {
|
|
201
|
+
const rCount = this.scheduler.runningCount;
|
|
202
|
+
const qCount = this.scheduler.queuedCount;
|
|
203
|
+
this.runningCountSig.set(rCount);
|
|
204
|
+
this.queuedCountSig.set(qCount);
|
|
205
|
+
const isWorkActive = rCount > 0 || qCount > 0;
|
|
206
|
+
this.runningSig.set(rCount > 0);
|
|
207
|
+
this.updatePendingState(isWorkActive);
|
|
208
|
+
if (isWorkActive) {
|
|
209
|
+
this.statusSig.set('pending');
|
|
210
|
+
}
|
|
211
|
+
else if (this.executionCountSig() > 0) {
|
|
212
|
+
this.statusSig.set('settled');
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
this.statusSig.set('idle');
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
updatePendingState(isWorkActive) {
|
|
219
|
+
const delay = this.options?.pendingDelay ?? 0;
|
|
220
|
+
const minDuration = this.options?.minimumPendingDuration ?? 0;
|
|
221
|
+
if (isWorkActive) {
|
|
222
|
+
if (this.pendingSig()) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
if (delay > 0) {
|
|
226
|
+
if (!this.pendingTimer) {
|
|
227
|
+
this.pendingTimer = setTimeout(() => {
|
|
228
|
+
this.pendingTimer = undefined;
|
|
229
|
+
if (this.scheduler.runningCount > 0 || this.scheduler.queuedCount > 0) {
|
|
230
|
+
this.pendingActiveTime = Date.now();
|
|
231
|
+
this.pendingSig.set(true);
|
|
232
|
+
}
|
|
233
|
+
}, delay);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
this.pendingActiveTime = Date.now();
|
|
238
|
+
this.pendingSig.set(true);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
if (this.pendingTimer) {
|
|
243
|
+
clearTimeout(this.pendingTimer);
|
|
244
|
+
this.pendingTimer = undefined;
|
|
245
|
+
}
|
|
246
|
+
if (this.pendingSig()) {
|
|
247
|
+
const elapsed = this.pendingActiveTime ? Date.now() - this.pendingActiveTime : minDuration;
|
|
248
|
+
const remaining = minDuration - elapsed;
|
|
249
|
+
if (remaining > 0) {
|
|
250
|
+
setTimeout(() => {
|
|
251
|
+
if (this.scheduler.runningCount === 0 && this.scheduler.queuedCount === 0) {
|
|
252
|
+
this.pendingSig.set(false);
|
|
253
|
+
this.pendingActiveTime = undefined;
|
|
254
|
+
}
|
|
255
|
+
}, remaining);
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
this.pendingSig.set(false);
|
|
259
|
+
this.pendingActiveTime = undefined;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
initScheduler(options) {
|
|
265
|
+
const policy = options?.concurrency ?? 'drop';
|
|
266
|
+
if (typeof policy === 'object' && policy.mode === 'parallel') {
|
|
267
|
+
return new parallel_scheduler_js_1.ParallelScheduler({
|
|
268
|
+
limit: policy.limit,
|
|
269
|
+
maxQueueSize: options?.maxQueueSize,
|
|
270
|
+
overflowPolicy: options?.overflowPolicy,
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
switch (policy) {
|
|
274
|
+
case 'restart':
|
|
275
|
+
return new restart_scheduler_js_1.RestartScheduler();
|
|
276
|
+
case 'enqueue':
|
|
277
|
+
return new enqueue_scheduler_js_1.EnqueueScheduler({
|
|
278
|
+
maxQueueSize: options?.maxQueueSize,
|
|
279
|
+
overflowPolicy: options?.overflowPolicy,
|
|
280
|
+
});
|
|
281
|
+
case 'latest':
|
|
282
|
+
return new latest_scheduler_js_1.LatestScheduler();
|
|
283
|
+
case 'drop':
|
|
284
|
+
default:
|
|
285
|
+
return new drop_scheduler_js_1.DropScheduler();
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
initDestroyRef(options) {
|
|
289
|
+
let destroyRef = null;
|
|
290
|
+
if (options?.injector) {
|
|
291
|
+
destroyRef = options.injector.get(core_1.DestroyRef, null);
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
try {
|
|
295
|
+
destroyRef = (0, core_1.inject)(core_1.DestroyRef, { optional: true });
|
|
296
|
+
}
|
|
297
|
+
catch {
|
|
298
|
+
// Ignored outside DI context
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
const destroyBehavior = options?.destroyBehavior ?? 'cancel';
|
|
302
|
+
if (destroyRef && destroyBehavior === 'cancel') {
|
|
303
|
+
destroyRef.onDestroy(() => {
|
|
304
|
+
this.cancelAll('Owner destroyed');
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
function createTask(handler, options) {
|
|
310
|
+
return new TaskImpl(handler, options);
|
|
311
|
+
}
|
|
312
|
+
//# sourceMappingURL=create-task.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-task.js","sourceRoot":"","sources":["../../../projects/ngx-task/src/lib/angular/create-task.ts"],"names":[],"mappings":";;AAwWA,gCAKC;AA7WD,wCAA6F;AAG7F,mFAA2E;AAE3E,uEAA+F;AAC/F,6EAA6F;AAE7F,uEAAgE;AAChE,6EAAsE;AACtE,6EAAsE;AACtE,2EAAoE;AACpE,+EAAwE;AAQxE,MAAM,iBAAiB;IAqBQ;IApBpB,EAAE,CAAS;IACX,IAAI,CAAQ;IACZ,SAAS,CAAS;IAEV,SAAS,CAAsC;IAC/C,WAAW,CAA2C;IACtD,SAAS,CAAsC;IAC/C,QAAQ,CAAwC;IAChD,YAAY,CAAqC;IACjD,aAAa,CAAqC;IAE1D,MAAM,CAA8B;IACpC,QAAQ,CAAmC;IAC3C,MAAM,CAA8B;IACpC,KAAK,CAAgC;IACrC,SAAS,CAA6B;IACtC,UAAU,CAA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C/C,KAAK,MAAM,CAAC;YACZ;gBACE,OAAO,IAAI,iCAAa,EAAkB,CAAC;QAC/C,CAAC;IACH,CAAC;IAEO,cAAc,CAAC,OAA2C;QAChE,IAAI,UAAU,GAAsB,IAAI,CAAC;QACzC,IAAI,OAAO,EAAE,QAAQ,EAAE,CAAC;YACtB,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,iBAAU,EAAE,IAAI,CAAC,CAAC;QACtD,CAAC;aAAM,CAAC;YACN,IAAI,CAAC;gBACH,UAAU,GAAG,IAAA,aAAM,EAAC,iBAAU,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;YACtD,CAAC;YAAC,MAAM,CAAC;gBACP,6BAA6B;YAC/B,CAAC;QACH,CAAC;QAED,MAAM,eAAe,GAAG,OAAO,EAAE,eAAe,IAAI,QAAQ,CAAC;QAC7D,IAAI,UAAU,IAAI,eAAe,KAAK,QAAQ,EAAE,CAAC;YAC/C,UAAU,CAAC,SAAS,CAAC,GAAG,EAAE;gBACxB,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC;YACpC,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF;AAED,SAAgB,UAAU,CACxB,OAAoC,EACpC,OAA2C;IAE3C,OAAO,IAAI,QAAQ,CAAiB,OAAO,EAAE,OAAO,CAAC,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Signal, Injector } from '@angular/core';
|
|
2
|
+
import type { TaskExecutionStatus, TaskStatus, TaskProgress, TaskError, ConcurrencyPolicy, QueueOverflowPolicy } from '../core/types.js';
|
|
3
|
+
import type { TaskOutcome } from '../core/outcome.js';
|
|
4
|
+
import type { TaskContext } from '../core/task-context.js';
|
|
5
|
+
import type { ObservableResultPolicy } from '../adapters/observable-adapter.js';
|
|
6
|
+
export type TaskHandler<TArgs, TResult> = (args: TArgs, context: TaskContext) => PromiseLike<TResult> | any;
|
|
7
|
+
export type DestroyBehavior = 'cancel' | 'detach' | 'allow';
|
|
8
|
+
export interface TaskTimeoutOptions {
|
|
9
|
+
readonly milliseconds: number;
|
|
10
|
+
readonly message?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface CreateTaskOptions<TArgs, TResult> {
|
|
13
|
+
concurrency?: ConcurrencyPolicy;
|
|
14
|
+
timeout?: number | TaskTimeoutOptions;
|
|
15
|
+
pendingDelay?: number;
|
|
16
|
+
minimumPendingDuration?: number;
|
|
17
|
+
classifyError?: (error: unknown) => TaskError;
|
|
18
|
+
destroyBehavior?: DestroyBehavior;
|
|
19
|
+
injector?: Injector;
|
|
20
|
+
maxQueueSize?: number;
|
|
21
|
+
overflowPolicy?: QueueOverflowPolicy;
|
|
22
|
+
observableResult?: ObservableResultPolicy;
|
|
23
|
+
}
|
|
24
|
+
export interface TaskExecution<TArgs, TResult> {
|
|
25
|
+
readonly id: string;
|
|
26
|
+
readonly args: TArgs;
|
|
27
|
+
readonly status: Signal<TaskExecutionStatus>;
|
|
28
|
+
readonly progress: Signal<TaskProgress | undefined>;
|
|
29
|
+
readonly result: Signal<TResult | undefined>;
|
|
30
|
+
readonly error: Signal<TaskError | undefined>;
|
|
31
|
+
readonly createdAt: number;
|
|
32
|
+
readonly startedAt: Signal<number | undefined>;
|
|
33
|
+
readonly finishedAt: Signal<number | undefined>;
|
|
34
|
+
readonly done: Promise<TaskOutcome<TResult>>;
|
|
35
|
+
cancel(reason?: unknown): void;
|
|
36
|
+
resultOrThrow(): Promise<TResult>;
|
|
37
|
+
}
|
|
38
|
+
export interface Task<TArgs, TResult> {
|
|
39
|
+
readonly status: Signal<TaskStatus>;
|
|
40
|
+
readonly pending: Signal<boolean>;
|
|
41
|
+
readonly running: Signal<boolean>;
|
|
42
|
+
readonly result: Signal<TResult | undefined>;
|
|
43
|
+
readonly error: Signal<TaskError | undefined>;
|
|
44
|
+
readonly progress: Signal<TaskProgress | undefined>;
|
|
45
|
+
readonly runningCount: Signal<number>;
|
|
46
|
+
readonly queuedCount: Signal<number>;
|
|
47
|
+
readonly executionCount: Signal<number>;
|
|
48
|
+
readonly lastExecution: Signal<TaskExecution<TArgs, TResult> | undefined>;
|
|
49
|
+
run(args: TArgs): TaskExecution<TArgs, TResult>;
|
|
50
|
+
cancel(reason?: unknown): void;
|
|
51
|
+
cancelAll(reason?: unknown): void;
|
|
52
|
+
reset(): void;
|
|
53
|
+
retryLast(): TaskExecution<TArgs, TResult> | undefined;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=task.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task.interface.d.ts","sourceRoot":"","sources":["../../../projects/ngx-task/src/lib/angular/task.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,KAAK,EACV,mBAAmB,EACnB,UAAU,EACV,YAAY,EACZ,SAAS,EACT,iBAAiB,EACjB,mBAAmB,EACpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE3D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAEhF,MAAM,MAAM,WAAW,CAAC,KAAK,EAAE,OAAO,IAAI,CACxC,IAAI,EAAE,KAAK,EACX,OAAO,EAAE,WAAW,KACjB,WAAW,CAAC,OAAO,CAAC,GAAG,GAAG,CAAC;AAEhC,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,CAAC;AAE5D,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,iBAAiB,CAAC,KAAK,EAAE,OAAO;I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import type { TaskExecutionStatus, TaskError, TaskProgress } from './types.js';
|
|
2
|
+
import type { TaskOutcome } from './outcome.js';
|
|
3
|
+
import type { TaskContext } from './task-context.js';
|
|
4
|
+
export interface ExecutionListener<TArgs, TResult> {
|
|
5
|
+
onStatusChange?: (status: TaskExecutionStatus) => void;
|
|
6
|
+
onProgressChange?: (progress: TaskProgress | undefined) => void;
|
|
7
|
+
onResultChange?: (result: TResult | undefined) => void;
|
|
8
|
+
onErrorChange?: (error: TaskError | undefined) => void;
|
|
9
|
+
}
|
|
10
|
+
export declare class ExecutionStateMachine<TArgs, TResult> {
|
|
11
|
+
readonly id: string;
|
|
12
|
+
readonly args: TArgs;
|
|
13
|
+
readonly createdAt: number;
|
|
14
|
+
readonly attempt: number;
|
|
15
|
+
readonly idempotencyKey: string;
|
|
16
|
+
private _status;
|
|
17
|
+
private _startedAt?;
|
|
18
|
+
private _finishedAt?;
|
|
19
|
+
private _progress?;
|
|
20
|
+
private _result?;
|
|
21
|
+
private _error?;
|
|
22
|
+
readonly abortController: AbortController;
|
|
23
|
+
readonly done: Promise<TaskOutcome<TResult>>;
|
|
24
|
+
private resolveDone;
|
|
25
|
+
private listeners;
|
|
26
|
+
constructor(id: string, args: TArgs, attempt?: number, idempotencyKey?: string);
|
|
27
|
+
get status(): TaskExecutionStatus;
|
|
28
|
+
get startedAt(): number | undefined;
|
|
29
|
+
get finishedAt(): number | undefined;
|
|
30
|
+
get progress(): TaskProgress | undefined;
|
|
31
|
+
get result(): TResult | undefined;
|
|
32
|
+
get error(): TaskError | undefined;
|
|
33
|
+
get isSettled(): boolean;
|
|
34
|
+
get isRunning(): boolean;
|
|
35
|
+
get isQueued(): boolean;
|
|
36
|
+
get signal(): AbortSignal;
|
|
37
|
+
addListener(listener: ExecutionListener<TArgs, TResult>): () => void;
|
|
38
|
+
createContext(reportProgressOverride?: (p: TaskProgress) => void): TaskContext;
|
|
39
|
+
queue(): boolean;
|
|
40
|
+
start(): boolean;
|
|
41
|
+
succeed(value: TResult): boolean;
|
|
42
|
+
fail(error: TaskError): boolean;
|
|
43
|
+
cancel(reason?: unknown): boolean;
|
|
44
|
+
supersede(): boolean;
|
|
45
|
+
drop(): boolean;
|
|
46
|
+
timeOut(error: TaskError): boolean;
|
|
47
|
+
reportProgress(progress: TaskProgress): void;
|
|
48
|
+
resultOrThrow(): Promise<TResult>;
|
|
49
|
+
private notifyStatus;
|
|
50
|
+
private notifyResult;
|
|
51
|
+
private notifyError;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=execution-state-machine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execution-state-machine.d.ts","sourceRoot":"","sources":["../../../projects/ngx-task/src/lib/core/execution-state-machine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,MAAM,WAAW,iBAAiB,CAAC,KAAK,EAAE,OAAO;IAC/C,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,mBAAmB,KAAK,IAAI,CAAC;IACvD,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,YAAY,GAAG,SAAS,KAAK,IAAI,CAAC;IAChE,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,GAAG,SAAS,KAAK,IAAI,CAAC;IACvD,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,KAAK,IAAI,CAAC;CACxD;AAWD,qBAAa,qBAAqB,CAAC,KAAK,EAAE,OAAO;IAC/C,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IACrB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC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hB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO;IAchC,IAAI,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO;IAc/B,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,OAAO;IAWjC,SAAS,IAAI,OAAO;IAUpB,IAAI,IAAI,OAAO;IASf,OAAO,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO;IAYlC,cAAc,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI;IAQtC,aAAa,IAAI,OAAO,CAAC,OAAO,CAAC;IAiBvC,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,WAAW;CAKpB"}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExecutionStateMachine = void 0;
|
|
4
|
+
const SETTLED_STATUSES = new Set([
|
|
5
|
+
'succeeded',
|
|
6
|
+
'failed',
|
|
7
|
+
'cancelled',
|
|
8
|
+
'superseded',
|
|
9
|
+
'dropped',
|
|
10
|
+
'timed-out',
|
|
11
|
+
]);
|
|
12
|
+
class ExecutionStateMachine {
|
|
13
|
+
id;
|
|
14
|
+
args;
|
|
15
|
+
createdAt;
|
|
16
|
+
attempt;
|
|
17
|
+
idempotencyKey;
|
|
18
|
+
_status = 'created';
|
|
19
|
+
_startedAt;
|
|
20
|
+
_finishedAt;
|
|
21
|
+
_progress;
|
|
22
|
+
_result;
|
|
23
|
+
_error;
|
|
24
|
+
abortController = new AbortController();
|
|
25
|
+
done;
|
|
26
|
+
resolveDone;
|
|
27
|
+
listeners = new Set();
|
|
28
|
+
constructor(id, args, attempt = 1, idempotencyKey) {
|
|
29
|
+
this.id = id;
|
|
30
|
+
this.args = args;
|
|
31
|
+
this.createdAt = Date.now();
|
|
32
|
+
this.attempt = attempt;
|
|
33
|
+
this.idempotencyKey = idempotencyKey ?? id;
|
|
34
|
+
this.done = new Promise((resolve) => {
|
|
35
|
+
this.resolveDone = resolve;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
get status() {
|
|
39
|
+
return this._status;
|
|
40
|
+
}
|
|
41
|
+
get startedAt() {
|
|
42
|
+
return this._startedAt;
|
|
43
|
+
}
|
|
44
|
+
get finishedAt() {
|
|
45
|
+
return this._finishedAt;
|
|
46
|
+
}
|
|
47
|
+
get progress() {
|
|
48
|
+
return this._progress;
|
|
49
|
+
}
|
|
50
|
+
get result() {
|
|
51
|
+
return this._result;
|
|
52
|
+
}
|
|
53
|
+
get error() {
|
|
54
|
+
return this._error;
|
|
55
|
+
}
|
|
56
|
+
get isSettled() {
|
|
57
|
+
return SETTLED_STATUSES.has(this._status);
|
|
58
|
+
}
|
|
59
|
+
get isRunning() {
|
|
60
|
+
return this._status === 'running';
|
|
61
|
+
}
|
|
62
|
+
get isQueued() {
|
|
63
|
+
return this._status === 'queued';
|
|
64
|
+
}
|
|
65
|
+
get signal() {
|
|
66
|
+
return this.abortController.signal;
|
|
67
|
+
}
|
|
68
|
+
addListener(listener) {
|
|
69
|
+
this.listeners.add(listener);
|
|
70
|
+
return () => this.listeners.delete(listener);
|
|
71
|
+
}
|
|
72
|
+
createContext(reportProgressOverride) {
|
|
73
|
+
return {
|
|
74
|
+
signal: this.signal,
|
|
75
|
+
executionId: this.id,
|
|
76
|
+
attempt: this.attempt,
|
|
77
|
+
idempotencyKey: this.idempotencyKey,
|
|
78
|
+
reportProgress: (progress) => {
|
|
79
|
+
if (reportProgressOverride) {
|
|
80
|
+
reportProgressOverride(progress);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
this.reportProgress(progress);
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
throwIfCancelled: () => {
|
|
87
|
+
if (this.signal.aborted) {
|
|
88
|
+
throw this.signal.reason ?? new Error(`Task execution ${this.id} was cancelled.`);
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
queue() {
|
|
94
|
+
if (this._status !== 'created')
|
|
95
|
+
return false;
|
|
96
|
+
this._status = 'queued';
|
|
97
|
+
this.notifyStatus();
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
start() {
|
|
101
|
+
if (this._status !== 'created' && this._status !== 'queued')
|
|
102
|
+
return false;
|
|
103
|
+
this._status = 'running';
|
|
104
|
+
this._startedAt = Date.now();
|
|
105
|
+
this.notifyStatus();
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
succeed(value) {
|
|
109
|
+
if (this._status !== 'running') {
|
|
110
|
+
// Late resolution ignored after settlement
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
this._status = 'succeeded';
|
|
114
|
+
this._result = value;
|
|
115
|
+
this._finishedAt = Date.now();
|
|
116
|
+
this.notifyStatus();
|
|
117
|
+
this.notifyResult();
|
|
118
|
+
this.resolveDone({ type: 'success', value });
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
fail(error) {
|
|
122
|
+
if (this._status !== 'running') {
|
|
123
|
+
// Late rejection ignored after settlement
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
this._status = 'failed';
|
|
127
|
+
this._error = error;
|
|
128
|
+
this._finishedAt = Date.now();
|
|
129
|
+
this.notifyStatus();
|
|
130
|
+
this.notifyError();
|
|
131
|
+
this.resolveDone({ type: 'failure', error });
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
cancel(reason) {
|
|
135
|
+
if (this.isSettled)
|
|
136
|
+
return false;
|
|
137
|
+
const wasRunningOrQueued = this._status === 'running' || this._status === 'queued';
|
|
138
|
+
this._status = 'cancelled';
|
|
139
|
+
this._finishedAt = Date.now();
|
|
140
|
+
this.abortController.abort(reason ?? 'cancelled');
|
|
141
|
+
this.notifyStatus();
|
|
142
|
+
this.resolveDone({ type: 'cancelled', reason });
|
|
143
|
+
return wasRunningOrQueued;
|
|
144
|
+
}
|
|
145
|
+
supersede() {
|
|
146
|
+
if (this.isSettled)
|
|
147
|
+
return false;
|
|
148
|
+
this._status = 'superseded';
|
|
149
|
+
this._finishedAt = Date.now();
|
|
150
|
+
this.abortController.abort('superseded');
|
|
151
|
+
this.notifyStatus();
|
|
152
|
+
this.resolveDone({ type: 'superseded' });
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
drop() {
|
|
156
|
+
if (this._status !== 'created')
|
|
157
|
+
return false;
|
|
158
|
+
this._status = 'dropped';
|
|
159
|
+
this._finishedAt = Date.now();
|
|
160
|
+
this.notifyStatus();
|
|
161
|
+
this.resolveDone({ type: 'dropped' });
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
timeOut(error) {
|
|
165
|
+
if (this._status !== 'running')
|
|
166
|
+
return false;
|
|
167
|
+
this._status = 'timed-out';
|
|
168
|
+
this._error = error;
|
|
169
|
+
this._finishedAt = Date.now();
|
|
170
|
+
this.abortController.abort('timed-out');
|
|
171
|
+
this.notifyStatus();
|
|
172
|
+
this.notifyError();
|
|
173
|
+
this.resolveDone({ type: 'timed-out', error });
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
reportProgress(progress) {
|
|
177
|
+
if (this.isSettled)
|
|
178
|
+
return;
|
|
179
|
+
this._progress = progress;
|
|
180
|
+
for (const listener of this.listeners) {
|
|
181
|
+
listener.onProgressChange?.(progress);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
async resultOrThrow() {
|
|
185
|
+
const outcome = await this.done;
|
|
186
|
+
switch (outcome.type) {
|
|
187
|
+
case 'success':
|
|
188
|
+
return outcome.value;
|
|
189
|
+
case 'failure':
|
|
190
|
+
case 'timed-out':
|
|
191
|
+
throw outcome.error.cause ?? new Error(outcome.error.message);
|
|
192
|
+
case 'cancelled':
|
|
193
|
+
throw outcome.reason ?? new Error(`Task execution ${this.id} was cancelled.`);
|
|
194
|
+
case 'superseded':
|
|
195
|
+
throw new Error(`Task execution ${this.id} was superseded.`);
|
|
196
|
+
case 'dropped':
|
|
197
|
+
throw new Error(`Task execution ${this.id} was dropped.`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
notifyStatus() {
|
|
201
|
+
for (const listener of this.listeners) {
|
|
202
|
+
listener.onStatusChange?.(this._status);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
notifyResult() {
|
|
206
|
+
for (const listener of this.listeners) {
|
|
207
|
+
listener.onResultChange?.(this._result);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
notifyError() {
|
|
211
|
+
for (const listener of this.listeners) {
|
|
212
|
+
listener.onErrorChange?.(this._error);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
exports.ExecutionStateMachine = ExecutionStateMachine;
|
|
217
|
+
//# sourceMappingURL=execution-state-machine.js.map
|