fix: bind admin state to request and page lifecycles

This commit is contained in:
illusia committed 2026-10-01 12:11:47 +08:00
1 parent 0785f82386
commit 525f512f4a
11 files changed
+1175 -229

No files matched your search

+20
View File
@@ -0,0 +1,20 @@
/** Ownership for one feature's in-flight work; reads with the same key replace
* each other, while unrelated features can continue independently. */
export function createAdminRequests() {
const pending = new Map<string, AbortController>();
function cancel(key: string): void {
pending.get(key)?.abort();
pending.delete(key);
}
return {
begin(key: string) {
cancel(key);
const controller = new AbortController();
pending.set(key, controller);
const isCurrent = () => pending.get(key) === controller && !controller.signal.aborted;
return { signal: controller.signal, isCurrent, finish() { if (isCurrent()) pending.delete(key); } };
},
cancel,
reset() { for (const key of pending.keys()) cancel(key); },
};
}