chore: cleanup

This commit is contained in:
adamelmore
2026-01-28 07:28:03 -06:00
parent c9bbea4266
commit acb92fcd34
2 changed files with 7 additions and 17 deletions
+5 -12
View File
@@ -1,5 +1,4 @@
import { Log } from "@/util/log"
import { withTimeout } from "@/util/timeout"
export namespace State {
interface Entry {
@@ -8,7 +7,6 @@ export namespace State {
}
const log = Log.create({ service: "state" })
const DISPOSE_TIMEOUT_MS = 10_000
const recordsByKey = new Map<string, Map<any, Entry>>()
export function create<S>(root: () => string, init: () => S, dispose?: (state: Awaited<S>) => Promise<void>) {
@@ -53,16 +51,11 @@ export namespace State {
const label = typeof init === "function" ? init.name : String(init)
const task = withTimeout(
Promise.resolve(entry.state).then((state) => entry.dispose!(state)),
DISPOSE_TIMEOUT_MS,
).catch((error) => {
if (error instanceof Error && error.message.includes("Operation timed out")) {
log.warn("state disposal timed out", { key, init: label })
return
}
log.error("Error while disposing state:", { error, key, init: label })
})
const task = Promise.resolve(entry.state)
.then((state) => entry.dispose!(state))
.catch((error) => {
log.error("Error while disposing state:", { error, key, init: label })
})
tasks.push(task)
}