def tmuxio_repeat_timeout( thunk: Callable[[], TmuxIO[A]], check: Callable[[A], bool], error: str, timeout: float, interval: float = None, ) -> Do: effective_interval = .01 if interval is None else interval start = yield TmuxIO.simple(time.time) @do(TmuxIO[None]) def wait_and_recurse() -> Do: yield TmuxIO.sleep(effective_interval) yield recurse() @do(TmuxIO[None]) def recurse() -> Do: result = yield thunk() done = check(result) yield (TmuxIO.pure(result) if done else TmuxIO.error(error) if time.time() - start > timeout else wait_and_recurse()) yield recurse()
def simple(self, f: Callable[..., A], *a: Any, **kw: Any) -> 'TmuxIOState[S, A]': return TS.lift(TmuxIO.simple(f, *a, **kw))