@gen.coroutine
def yield_for_all_futures(result):
 while True:
  try:
   future = gen.convert_yielded(result)
  except gen.BadYieldError:
   break
  else:
   result = (yield future)
 raise gen.Return(result)

@ gen . coroutine def yield_for_all_futures ( result ) : while True : try : future = gen . convert_yielded ( result ) except gen . BadYieldError : break else : result = ( yield future ) raise gen . Return ( result )
converts result into a future by collapsing any futures inside result .