Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 3026x 3026x 2821x 2821x 3026x 3026x 2821x | export async function abortable<T>(signal: AbortSignal, promise: Promise<T>): Promise<T> {
signal.throwIfAborted()
let abortHandler: () => void
let abortPromise = new Promise<T>((_, reject) => {
abortHandler = () => reject(signal.reason)
signal.addEventListener('abort', abortHandler, { once: true })
})
try {
return await Promise.race<T>([promise, abortPromise])
} finally {
Eif (abortHandler!) signal.removeEventListener('abort', abortHandler)
}
}
|