def loop_until_state_found(reactor, get_states, state_matches, timeout):
 def state_reached():
  d = get_states()
  def find_match(states):
   for state in states:
    if state_matches(state):
     return state
   return None
  d.addCallback(find_match)
  return d
 d = loop_until(reactor, state_reached)
 _timeout(reactor, d, timeout.total_seconds())
 return d

def loop_until_state_found ( reactor , get_states , state_matches , timeout ) : def state_reached ( ) : d = get_states ( ) def find_match ( states ) : for state in states : if state_matches ( state ) : return state return None d . addCallback ( find_match ) return d d = loop_until ( reactor , state_reached ) _timeout ( reactor , d , timeout . total_seconds ( ) ) return d
loop until a state has been reached .