pi-simple-background-tasks 0.0.0-stage → 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/FORK-CHANGES.md +66 -0
- package/LICENSE +15 -0
- package/README.md +100 -2
- package/package.json +59 -4
- package/src/core/common.ts +914 -0
- package/src/core/config.ts +83 -0
- package/src/core/durable-fs.ts +545 -0
- package/src/core/extension-api.ts +70 -0
- package/src/core/lazy-module.ts +55 -0
- package/src/core/registry.ts +2426 -0
- package/src/core/reload-shell-owner.ts +1512 -0
- package/src/core/shell-policy.ts +180 -0
- package/src/core/task-cleanup.ts +146 -0
- package/src/core/task-durable.ts +65 -0
- package/src/core/windows-taskkill.ts +263 -0
- package/src/extension.ts +928 -0
- package/src/ui/background-tasks-manager.ts +731 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Activation-local synchronous close barrier. Every registered callback runs on
|
|
3
|
+
* close(), in registration order, and a throwing callback does not prevent the
|
|
4
|
+
* later ones (failures are aggregated). Used to close every lazy lane on the same
|
|
5
|
+
* call stack during a Pi reload or shutdown.
|
|
6
|
+
*/
|
|
7
|
+
export class SynchronousActivationCloseFence {
|
|
8
|
+
private closed = false;
|
|
9
|
+
private readonly callbacks = new Set<() => void>();
|
|
10
|
+
|
|
11
|
+
add(callback: () => void): void {
|
|
12
|
+
this.callbacks.add(callback);
|
|
13
|
+
if (this.closed) callback();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
close(): void {
|
|
17
|
+
this.closed = true;
|
|
18
|
+
const failures: unknown[] = [];
|
|
19
|
+
for (const callback of this.callbacks) {
|
|
20
|
+
try {
|
|
21
|
+
callback();
|
|
22
|
+
} catch (error) {
|
|
23
|
+
failures.push(error);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (failures.length > 0) {
|
|
27
|
+
throw new AggregateError(failures, `close barrier failed in ${failures.length} callback(s)`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Activation-local single-flight memo for one deferred import. The module loads
|
|
34
|
+
* once on the first `run` and every later call reuses the same promise. After
|
|
35
|
+
* `close()` (a Pi reload or shutdown) a racing `run` is rejected so the stale
|
|
36
|
+
* activation never touches the freshly reloaded runtime.
|
|
37
|
+
*/
|
|
38
|
+
export class LazyModule<T> {
|
|
39
|
+
private module: Promise<T> | undefined;
|
|
40
|
+
private closed = false;
|
|
41
|
+
|
|
42
|
+
constructor(private readonly importer: () => Promise<T>) {}
|
|
43
|
+
|
|
44
|
+
close(): void {
|
|
45
|
+
this.closed = true;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async run<R>(operation: (module: T) => R | Promise<R>): Promise<R> {
|
|
49
|
+
if (this.closed) throw new Error('activation closed');
|
|
50
|
+
this.module ??= this.importer();
|
|
51
|
+
const value = await this.module;
|
|
52
|
+
if (this.closed) throw new Error('activation closed');
|
|
53
|
+
return operation(value);
|
|
54
|
+
}
|
|
55
|
+
}
|