From c818362773ac8c2cb2b862ef4af5c6df676db39c Mon Sep 17 00:00:00 2001 From: Bauke Date: Sat, 15 Jul 2023 21:19:41 +0200 Subject: [PATCH] Add a sleep utility function. --- source/utilities/exports.ts | 1 + source/utilities/sleep.ts | 9 +++++++++ 2 files changed, 10 insertions(+) create mode 100644 source/utilities/sleep.ts diff --git a/source/utilities/exports.ts b/source/utilities/exports.ts index bd997ce..72bd8a6 100644 --- a/source/utilities/exports.ts +++ b/source/utilities/exports.ts @@ -7,6 +7,7 @@ export * from "./http.js"; export * from "./logging.js"; export * from "./query-selectors.js"; export * from "./report-a-bug.js"; +export * from "./sleep.js"; export * from "./text.js"; export * from "./user.js"; export * from "./validators.js"; diff --git a/source/utilities/sleep.ts b/source/utilities/sleep.ts new file mode 100644 index 0000000..c1bcb2f --- /dev/null +++ b/source/utilities/sleep.ts @@ -0,0 +1,9 @@ +/** + * Promisified {@linkcode window.setTimeout}. + * @param timeout The amount of time in milliseconds to sleep for. + */ +export async function sleep(timeout: number): Promise { + return new Promise((resolve) => { + window.setTimeout(resolve, timeout); + }); +}