mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-01 14:52:25 +00:00
fix lsp diagnostic accurancy
This commit is contained in:
14
packages/opencode/src/util/timeout.ts
Normal file
14
packages/opencode/src/util/timeout.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
export function withTimeout<T>(promise: Promise<T>, ms: number): Promise<T> {
|
||||
let timeout: NodeJS.Timeout
|
||||
return Promise.race([
|
||||
promise.then((result) => {
|
||||
clearTimeout(timeout)
|
||||
return result
|
||||
}),
|
||||
new Promise<never>((_, reject) => {
|
||||
timeout = setTimeout(() => {
|
||||
reject(new Error(`Operation timed out after ${ms}ms`))
|
||||
}, ms)
|
||||
}),
|
||||
])
|
||||
}
|
||||
Reference in New Issue
Block a user