<s> from time import time , sleep <EOL> class TimeoutError ( Exception ) : <EOL> pass <EOL> class PreconditionError ( Exception ) : <EOL> pass <EOL> def await ( name , f , timeout = <NUM_LIT> , interval = <NUM_LIT:1> , precondition = None ) : <EOL> deadline = time ( ) + timeout <EOL> while time ( ) < deadline : <EOL> if precondition and not precondition ( ) : <EOL> raise PreconditionError ( name ) <EOL> value = f ( ) <EOL> if value : <EOL> return value <EOL> sleep ( interval ) <EOL> raise TimeoutError ( name ) </s>
