sleepUntil async support
This commit is contained in:
parent
51549db3d9
commit
19251244d2
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ztimson/utils",
|
"name": "@ztimson/utils",
|
||||||
"version": "0.16.1",
|
"version": "0.16.2",
|
||||||
"description": "Utility library",
|
"description": "Utility library",
|
||||||
"author": "Zak Timson",
|
"author": "Zak Timson",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
@ -39,12 +39,12 @@ export function sleep(ms: number): Promise<void> {
|
|||||||
* await sleepUntil(() => loading); // Won't continue until loading flag is false
|
* 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
|
* @param {number} checkInterval Run function ever x milliseconds
|
||||||
* @return {Promise<void>} Callback when sleep is over
|
* @return {Promise<void>} Callback when sleep is over
|
||||||
*/
|
*/
|
||||||
export async function sleepUntil(fn : () => boolean, checkInterval=100): Promise<void> {
|
export async function sleepUntil(fn : () => boolean | Promise<boolean>, checkInterval = 100): Promise<void> {
|
||||||
while(fn()) await sleep(checkInterval);
|
while(await fn()) await sleep(checkInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user