Spaces:
Running

MiniSearch / shared /withTimeout.ts
system's picture
system HF Staff
Sync from felladrin/MiniSearch@43edeee (part 2)
c0e51f5 verified
Raw History Blame Contribute Delete
289 Bytes
/** Aborts when `signal` does, or after `ms` milliseconds, whichever comes first. */
export function withTimeout(
signal: AbortSignal | undefined,
ms: number,
): AbortSignal {
const timeout = AbortSignal.timeout(ms);
return signal ? AbortSignal.any([signal, timeout]) : timeout;
}