code: def yield_for_all_futures(result):
      
      while True:
  
          # This is needed for Tornado >= 4.5 where convert_yielded will no
          # longer raise BadYieldError on None
          if result is None:
              break
  
          try:
              future = gen.convert_yielded(result)
          except gen.BadYieldError:
              # result is not a yieldable thing, we are done
              break
          else:
              result = yield future
  
      raise gen.Return(result)
docs: Converts result into a Future by collapsing any futures inside result.
  
      If result is a Future we yield until it's done, then if the value inside
      the Future is another Future we yield until it's done as well, and so on.