Renamed sleepUntil to sleepWhile, it was misleading
All checks were successful
Build / Build NPM Project (push) Successful in 1m5s
Build / Tag Version (push) Successful in 14s
Build / Publish Documentation (push) Successful in 39s

This commit is contained in:
Zakary Timson 2024-10-07 15:40:14 -04:00
parent 3e8f5cc00b
commit b93ed45521
3 changed files with 5 additions and 5 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "@ztimson/utils", "name": "@ztimson/utils",
"version": "0.17.2", "version": "0.18.0",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@ztimson/utils", "name": "@ztimson/utils",
"version": "0.17.2", "version": "0.18.0",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"var-persist": "^1.0.1" "var-persist": "^1.0.1"

View File

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

View File

@ -36,14 +36,14 @@ export function sleep(ms: number): Promise<void> {
* ```js * ```js
* let loading = true; * let loading = true;
* setTimeout(() => wait = false, 1000); * 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 {() => 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 | Promise<boolean>, checkInterval = 100): Promise<void> { export async function sleepWhile(fn : () => boolean | Promise<boolean>, checkInterval = 100): Promise<void> {
while(await fn()) await sleep(checkInterval); while(await fn()) await sleep(checkInterval);
} }