mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 03:52:50 +08:00
fix: bind admin state to request and page lifecycles
This commit is contained in:
1 parent
0785f82386
commit
525f512f4a
11 files changed
+1175
-229
No files matched your search
@@ -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); },
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user