mirror of
https://github.com/anomalyco/opencode.git
synced 2026-02-01 22:48:16 +00:00
chore: cleanup
This commit is contained in:
@@ -5,7 +5,6 @@ import { State } from "./state"
|
||||
import { iife } from "@/util/iife"
|
||||
import { GlobalBus } from "@/bus/global"
|
||||
import { Filesystem } from "@/util/filesystem"
|
||||
import { withTimeout } from "@/util/timeout"
|
||||
|
||||
interface Context {
|
||||
directory: string
|
||||
@@ -15,8 +14,6 @@ interface Context {
|
||||
const context = Context.create<Context>("instance")
|
||||
const cache = new Map<string, Promise<Context>>()
|
||||
|
||||
const DISPOSE_TIMEOUT_MS = 10_000
|
||||
|
||||
const disposal = {
|
||||
all: undefined as Promise<void> | undefined,
|
||||
}
|
||||
@@ -92,8 +89,8 @@ export const Instance = {
|
||||
for (const [key, value] of entries) {
|
||||
if (cache.get(key) !== value) continue
|
||||
|
||||
const ctx = await withTimeout(value, DISPOSE_TIMEOUT_MS).catch((error) => {
|
||||
Log.Default.warn("instance dispose timed out", { key, error })
|
||||
const ctx = await value.catch((error) => {
|
||||
Log.Default.warn("instance dispose failed", { key, error })
|
||||
return undefined
|
||||
})
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user