Renamed sleepUntil to sleepWhile, it was misleading
This commit is contained in:
parent
3e8f5cc00b
commit
b93ed45521
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@ztimson/utils",
|
||||
"version": "0.17.2",
|
||||
"version": "0.18.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@ztimson/utils",
|
||||
"version": "0.17.2",
|
||||
"version": "0.18.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"var-persist": "^1.0.1"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ztimson/utils",
|
||||
"version": "0.17.2",
|
||||
"version": "0.18.0",
|
||||
"description": "Utility library",
|
||||
"author": "Zak Timson",
|
||||
"license": "MIT",
|
||||
|
@ -36,14 +36,14 @@ export function sleep(ms: number): Promise<void> {
|
||||
* ```js
|
||||
* let loading = true;
|
||||
* setTimeout(() => wait = false, 1000);
|
||||
* await sleepUntil(() => loading); // Won't continue until loading flag is false
|
||||
* await sleepWhile(() => loading); // Won't continue until loading flag is false
|
||||
* ```
|
||||
*
|
||||
* @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 | Promise<boolean>, checkInterval = 100): Promise<void> {
|
||||
export async function sleepWhile(fn : () => boolean | Promise<boolean>, checkInterval = 100): Promise<void> {
|
||||
while(await fn()) await sleep(checkInterval);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user