<s> from rx . observable import Observable <EOL> from rx . anonymousobservable import AnonymousObservable <EOL> from rx . concurrency import timeout_scheduler <EOL> from rx . internal import extensionclassmethod <EOL> @ extensionclassmethod ( Observable ) <EOL> def generate_with_relative_time ( cls , initial_state , condition , iterate , <EOL> result_selector , time_selector , <EOL> scheduler = None ) : <EOL> """<STR_LIT>""" <EOL> scheduler = scheduler or timeout_scheduler <EOL> def subscribe ( observer ) : <EOL> state = [ initial_state ] <EOL> has_result = [ False ] <EOL> result = [ None ] <EOL> first = [ True ] <EOL> time = None <EOL> def action ( this ) : <EOL> if has_result [ <NUM_LIT:0> ] : <EOL> observer . on_next ( result [ <NUM_LIT:0> ] ) <EOL> try : <EOL> if first [ <NUM_LIT:0> ] : <EOL> first [ <NUM_LIT:0> ] = False <EOL> else : <EOL> state [ <NUM_LIT:0> ] = iterate ( state [ <NUM_LIT:0> ] ) <EOL> has_result [ <NUM_LIT:0> ] = condition ( state [ <NUM_LIT:0> ] ) <EOL> if has_result [ <NUM_LIT:0> ] : <EOL> result [ <NUM_LIT:0> ] = result_selector ( state [ <NUM_LIT:0> ] ) <EOL> time = time_selector ( state [ <NUM_LIT:0> ] ) <EOL> except Exception as e : <EOL> observer . on_error ( e ) <EOL> return <EOL> if has_result [ <NUM_LIT:0> ] : <EOL> this ( time ) <EOL> else : <EOL> observer . on_completed ( ) <EOL> return scheduler . schedule_recursive_with_relative ( <NUM_LIT:0> , action ) <EOL> return AnonymousObservable ( subscribe ) </s>
