Skip to content

Instantly share code, notes, and snippets.

@xantiagoma
Created February 7, 2025 03:50
Show Gist options
  • Save xantiagoma/6ea2b38caef346cf600c95c31b6187ac to your computer and use it in GitHub Desktop.
Save xantiagoma/6ea2b38caef346cf600c95c31b6187ac to your computer and use it in GitHub Desktop.
export async function wait(ms: number): Promise<void>;
export async function wait<T>(ms: number, value: T): Promise<T>;
export async function wait<T>(
ms: number,
value?: T | undefined,
): Promise<T | undefined> {
return new Promise<T | undefined>((resolve) =>
setTimeout(
() => (value === undefined ? resolve(undefined) : resolve(value)),
ms,
),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment