瀏覽代碼

chore: cleanup

adamelmore 3 周之前
父節點
當前提交
acb92fcd34
共有 2 個文件被更改,包括 7 次插入17 次删除
  1. 2 5
      packages/opencode/src/project/instance.ts
  2. 5 12
      packages/opencode/src/project/state.ts

+ 2 - 5
packages/opencode/src/project/instance.ts

@@ -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
         })
 

+ 5 - 12
packages/opencode/src/project/state.ts

@@ -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)
     }