Async wait for
npm install wait-for-async``tswait-for-async
import waitFor from ;
await waitFor({ interval, condition, times });
`
Wait for condition() to be true.interval
Its value is checked every milliseconds,times
check no more than intervals in total.
Whenever condition() becomes true, return true.condition()
If never becomes true until times intervals passed, return false.
The intervals (in milliseconds) on how often to check condition()'s value.100
The default value is .
At least 1 interval will be waited before condition() is checked,condition()
even if is true at the very beginning.
condition() is a method that returns true or false.() => true
The default value is .
How many times in total to check condition()'s value before giving up.Infinity
The default value is .
These are the maximum times to check. Fewer times to check if condition()'s value becomes true sooner.
true if condition() becomes true before giving up, otherwise return false.
Or simply put, condition()'s value will be returned.
Wait for the download to become true (this variable should be updated by the file downloading code).download
Check the value every second (the interval's default value is 100ms), and give up after 60 seconds(60 checks).
`ts``
await waitFor({ interval: 3000 });