fix: clear timeout after promise rejection (#24864)

This commit is contained in:
Luke Parker 2026-04-29 09:37:12 +10:00 committed by GitHub
parent 91bd295209
commit 9fbeafb63e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,9 +1,8 @@
export function withTimeout<T>(promise: Promise<T>, ms: number): Promise<T> {
let timeout: NodeJS.Timeout
return Promise.race([
promise.then((result) => {
promise.finally(() => {
clearTimeout(timeout)
return result
}),
new Promise<never>((_, reject) => {
timeout = setTimeout(() => {