diff --git a/client/vscode-lib/src/util/cache.ts b/client/vscode-lib/src/util/cache.ts index 55a7ec3e..8245b0a6 100644 --- a/client/vscode-lib/src/util/cache.ts +++ b/client/vscode-lib/src/util/cache.ts @@ -16,7 +16,7 @@ export class Cache { this.cache.set(key, { value }) const timeout = setTimeout(() => this.cache.delete(key), this.ttlMs) - timeout.unref() + if (typeof timeout !== 'number' && 'unref' in timeout) timeout.unref() return value } @@ -33,7 +33,7 @@ export async function bestEffort( let id: ReturnType | undefined const timeout = new Promise((resolve, _) => { id = setTimeout(resolve, opts.delay, opts.defaultValue) - id.unref() + if (typeof id !== 'number' && 'unref' in id) id.unref() }) try { return await Promise.race([promise, timeout]) diff --git a/client/vscode-lib/src/util/errorWaiter.ts b/client/vscode-lib/src/util/errorWaiter.ts index db0d3d8f..90b13d0c 100644 --- a/client/vscode-lib/src/util/errorWaiter.ts +++ b/client/vscode-lib/src/util/errorWaiter.ts @@ -50,11 +50,10 @@ export function createErrorWaiter(delay: number, errorCountThreshold: number): E if (!timeoutHandle) { return } - if ('unref' in timeoutHandle) { + if (typeof timeoutHandle !== 'number' && 'unref' in timeoutHandle) { timeoutHandle.unref() - } else if (typeof timeoutHandle === 'number') { - clearTimeout(timeoutHandle) } + clearTimeout(timeoutHandle) }, } } diff --git a/provider/devdocs/cache.ts b/provider/devdocs/cache.ts index 2f1950fd..77c609fb 100644 --- a/provider/devdocs/cache.ts +++ b/provider/devdocs/cache.ts @@ -16,7 +16,7 @@ export class Cache { this.cache.set(key, { value }) const timeout = setTimeout(() => this.cache.delete(key), this.timeoutMS) - timeout.unref() + if (typeof timeout !== 'number' && 'unref' in timeout) timeout.unref() return value }