Download src/proxy-capture/store-lifecycle.ts from SaylorTwift/openclaw: direct link, hf CLI and curl.
- Browser
- Download file 1.11 kB
-
https://huggingface.co/SaylorTwift/openclaw/resolve/main/src/proxy-capture/store-lifecycle.ts
- Command line
-
hf download hf://SaylorTwift/openclaw/src/proxy-capture/store-lifecycle.ts
-
curl -L -o store-lifecycle.ts https://huggingface.co/SaylorTwift/openclaw/resolve/main/src/proxy-capture/store-lifecycle.ts
1.11 kB
| // Capture sessions must settle while their exact store is still writable. | |
| // This registry avoids a runtime/store import cycle and never acquires a store. | |
| const finalizers = new WeakMap<object, Set<() => void>>(); | |
| const closed = new WeakSet<object>(); | |
| export function registerCaptureStoreFinalizer(store: object, finalize: () => void): () => void { | |
| if (closed.has(store)) { | |
| throw new Error("Capture store is already finalized."); | |
| } | |
| let callbacks = finalizers.get(store); | |
| if (!callbacks) { | |
| callbacks = new Set(); | |
| finalizers.set(store, callbacks); | |
| } | |
| callbacks.add(finalize); | |
| return () => callbacks.delete(finalize); | |
| } | |
| export function finalizeCaptureStore(store: object): void { | |
| if (closed.has(store)) { | |
| return; | |
| } | |
| closed.add(store); | |
| const callbacks = finalizers.get(store); | |
| finalizers.delete(store); | |
| const errors: unknown[] = []; | |
| for (const finalize of callbacks ?? []) { | |
| try { | |
| finalize(); | |
| } catch (error) { | |
| errors.push(error); | |
| } | |
| } | |
| if (errors.length) { | |
| throw new AggregateError(errors, "Capture store finalization failed."); | |
| } | |
| } | |