Skip to content

Commit

Permalink
Add time and sleep calls to runner, use them in loop_until
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhay Saxena committed Aug 30, 2018
1 parent fbdb0eb commit 105aac8
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions telepresence/runner/__init__.py
Expand Up @@ -244,6 +244,18 @@ def require(self, commands: typing.Iterable[str], message: str) -> None:

# Time

def time(self) -> float:
"""
Return the time in seconds since the epoch.
"""
return time()

def sleep(self, seconds: float) -> None:
"""
Suspend execution for the given number of seconds.
"""
sleep(seconds)

def loop_until(self, loop_seconds: float,
sleep_seconds: float) -> typing.Iterable[int]:
"""
Expand All @@ -254,14 +266,14 @@ def loop_until(self, loop_seconds: float,
:param sleep_seconds: How long to sleep between loops
:return: yields the loop counter, 0 onward
"""
end_time = time() + loop_seconds
end_time = self.time() + loop_seconds - sleep_seconds
counter = 0
yield counter
sleep(sleep_seconds)
while time() < end_time:
counter += 1
while True:
yield counter
sleep(sleep_seconds)
counter += 1
if self.time() >= end_time:
break
self.sleep(sleep_seconds)

# Subprocesses

Expand Down

0 comments on commit 105aac8

Please sign in to comment.