def fake_poll_until(retriever, condition=lambda value: value, sleep_time=1, time_out=0): """Fakes out poll until.""" from trove.common import exception slept_time = 0 while True: resource = retriever() if condition(resource): return resource fake_sleep(sleep_time) slept_time += sleep_time if time_out and slept_time >= time_out: raise exception.PollTimeOut()
def fake_poll_until(retriever, condition=lambda value: value, sleep_time=1, time_out=None): """Retrieves object until it passes condition, then returns it. If time_out_limit is passed in, PollTimeOut will be raised once that amount of time is eclipsed. """ slept_time = 0 while True: resource = retriever() if condition(resource): return resource event_simulator_sleep(sleep_time) slept_time += sleep_time if time_out and slept_time >= time_out: raise exception.PollTimeOut()