@polgubau/utils
Version:
A collection of utility functions for TypeScript
1 lines • 1 kB
Source Map (JSON)
{"version":3,"sources":["../../../../src/functions/sleep/sleep.ts"],"sourcesContent":["/**\n * Pauses the execution for a specified duration.\n *\n * @param {number | `${number}ms`} ms - The duration to sleep. It can be a number representing milliseconds or a string in the format `${number}ms`.\n * @returns {Promise<void>} A promise that resolves after the specified duration.\n *\n * @example Sleep for 1000 milliseconds\n * await sleep(1000);\n *\n * @example Sleep for 2 seconds\n * await sleep(\"2000ms\");\n */\nexport const sleep = (ms: number | `${number}ms`): Promise<void> => {\n let duration: number;\n if (typeof ms === \"string\") {\n duration = Number.parseInt(ms);\n } else {\n duration = ms;\n }\n return new Promise((resolve) => setTimeout(resolve, duration));\n};\n"],"mappings":";AAYO,IAAM,QAAQ,CAAC,OAA8C;AAClE,MAAI;AACJ,MAAI,OAAO,OAAO,UAAU;AAC1B,eAAW,OAAO,SAAS,EAAE;AAAA,EAC/B,OAAO;AACL,eAAW;AAAA,EACb;AACA,SAAO,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,QAAQ,CAAC;AAC/D;","names":[]}