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",
|
"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"
|
||||||
|
@ -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",
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user