mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-18 23:02:14 +00:00
18 lines
402 B
TypeScript
18 lines
402 B
TypeScript
/**
|
|
* Sleep helper that respects abort signal.
|
|
*/
|
|
export function sleep(ms: number, signal?: AbortSignal): Promise<void> {
|
|
return new Promise((resolve, reject) => {
|
|
if (signal?.aborted) {
|
|
reject(new Error("Aborted"));
|
|
return;
|
|
}
|
|
|
|
const timeout = setTimeout(resolve, ms);
|
|
|
|
signal?.addEventListener("abort", () => {
|
|
clearTimeout(timeout);
|
|
reject(new Error("Aborted"));
|
|
});
|
|
});
|
|
}
|