chore: cleanup
This commit is contained in:
@@ -5,7 +5,6 @@ import { State } from "./state"
|
|||||||
import { iife } from "@/util/iife"
|
import { iife } from "@/util/iife"
|
||||||
import { GlobalBus } from "@/bus/global"
|
import { GlobalBus } from "@/bus/global"
|
||||||
import { Filesystem } from "@/util/filesystem"
|
import { Filesystem } from "@/util/filesystem"
|
||||||
import { withTimeout } from "@/util/timeout"
|
|
||||||
|
|
||||||
interface Context {
|
interface Context {
|
||||||
directory: string
|
directory: string
|
||||||
@@ -15,8 +14,6 @@ interface Context {
|
|||||||
const context = Context.create<Context>("instance")
|
const context = Context.create<Context>("instance")
|
||||||
const cache = new Map<string, Promise<Context>>()
|
const cache = new Map<string, Promise<Context>>()
|
||||||
|
|
||||||
const DISPOSE_TIMEOUT_MS = 10_000
|
|
||||||
|
|
||||||
const disposal = {
|
const disposal = {
|
||||||
all: undefined as Promise<void> | undefined,
|
all: undefined as Promise<void> | undefined,
|
||||||
}
|
}
|
||||||
@@ -92,8 +89,8 @@ export const Instance = {
|
|||||||
for (const [key, value] of entries) {
|
for (const [key, value] of entries) {
|
||||||
if (cache.get(key) !== value) continue
|
if (cache.get(key) !== value) continue
|
||||||
|
|
||||||
const ctx = await withTimeout(value, DISPOSE_TIMEOUT_MS).catch((error) => {
|
const ctx = await value.catch((error) => {
|
||||||
Log.Default.warn("instance dispose timed out", { key, error })
|
Log.Default.warn("instance dispose failed", { key, error })
|
||||||
return undefined
|
return undefined
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { Log } from "@/util/log"
|
import { Log } from "@/util/log"
|
||||||
import { withTimeout } from "@/util/timeout"
|
|
||||||
|
|
||||||
export namespace State {
|
export namespace State {
|
||||||
interface Entry {
|
interface Entry {
|
||||||
@@ -8,7 +7,6 @@ export namespace State {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const log = Log.create({ service: "state" })
|
const log = Log.create({ service: "state" })
|
||||||
const DISPOSE_TIMEOUT_MS = 10_000
|
|
||||||
const recordsByKey = new Map<string, Map<any, Entry>>()
|
const recordsByKey = new Map<string, Map<any, Entry>>()
|
||||||
|
|
||||||
export function create<S>(root: () => string, init: () => S, dispose?: (state: Awaited<S>) => Promise<void>) {
|
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 label = typeof init === "function" ? init.name : String(init)
|
||||||
|
|
||||||
const task = withTimeout(
|
const task = Promise.resolve(entry.state)
|
||||||
Promise.resolve(entry.state).then((state) => entry.dispose!(state)),
|
.then((state) => entry.dispose!(state))
|
||||||
DISPOSE_TIMEOUT_MS,
|
.catch((error) => {
|
||||||
).catch((error) => {
|
log.error("Error while disposing state:", { error, key, init: label })
|
||||||
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 })
|
|
||||||
})
|
|
||||||
|
|
||||||
tasks.push(task)
|
tasks.push(task)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user