mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-22 12:11:26 +00:00
feature(utils): a hopefully reusable waitloop
This commit is contained in:
parent
1cefaefa3b
commit
6523105d89
15
selfprivacy_api/utils/waitloop.py
Normal file
15
selfprivacy_api/utils/waitloop.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
from time import sleep
|
||||
from typing import Callable
|
||||
from typing import Optional
|
||||
|
||||
def wait_until_true(readiness_checker: Callable[[],bool],*,interval: float =0.1, timeout_sec: Optional[float] = None):
|
||||
elapsed = 0.0
|
||||
if timeout_sec is None:
|
||||
timeout_sec = 10e16
|
||||
while not readiness_checker or elapsed > timeout_sec:
|
||||
sleep(interval)
|
||||
elapsed += interval
|
||||
if elapsed > timeout_sec:
|
||||
raise TimeoutError()
|
||||
|
||||
|
Loading…
Reference in a new issue