sleepUntil async support
All checks were successful
Build / Build NPM Project (push) Successful in 39s
Build / Tag Version (push) Successful in 8s

This commit is contained in:
Zakary Timson 2024-09-26 23:45:40 -04:00
parent 51549db3d9
commit 19251244d2
2 changed files with 4 additions and 4 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@ztimson/utils",
"version": "0.16.1",
"version": "0.16.2",
"description": "Utility library",
"author": "Zak Timson",
"license": "MIT",

View File

@ -39,12 +39,12 @@ export function sleep(ms: number): Promise<void> {
* await sleepUntil(() => loading); // Won't continue until loading flag is false
* ```
*
* @param {() => boolean} fn Return true to continue
* @param {() => boolean | Promise<boolean>} fn Return true to continue
* @param {number} checkInterval Run function ever x milliseconds
* @return {Promise<void>} Callback when sleep is over
*/
export async function sleepUntil(fn : () => boolean, checkInterval=100): Promise<void> {
while(fn()) await sleep(checkInterval);
export async function sleepUntil(fn : () => boolean | Promise<boolean>, checkInterval = 100): Promise<void> {
while(await fn()) await sleep(checkInterval);
}
/**