MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / withTimeout

Function withTimeout

cli/src/utils/terminal-color-detection.ts:28–46  ·  view source on GitHub ↗
(
  promise: Promise<T>,
  timeoutMs: number,
  timeoutValue: T,
)

Source from the content-addressed store, hash-verified

26 * @param timeoutValue - Value to return on timeout
27 */
28export function withTimeout<T>(
29 promise: Promise<T>,
30 timeoutMs: number,
31 timeoutValue: T,
32): Promise<T> {
33 let timeoutId: NodeJS.Timeout | null = null
34
35 const timeoutPromise = new Promise<T>((resolve) => {
36 timeoutId = setTimeout(() => {
37 resolve(timeoutValue)
38 }, timeoutMs)
39 })
40
41 return Promise.race([promise, timeoutPromise]).finally(() => {
42 if (timeoutId) {
43 clearTimeout(timeoutId)
44 }
45 })
46}
47
48/**
49 * Check if the current terminal supports OSC color queries

Callers 5

exitFreebuffCleanlyFunction · 0.90
exitCliFunction · 0.90
detectTerminalThemeFunction · 0.70

Calls 2

setTimeoutFunction · 0.85
resolveFunction · 0.70

Tested by

no test coverage detected