code: def as_completed(fs, *, timeout=None):
      """Return an iterator whose values are coroutines.
  
      When waiting for the yielded coroutines you'll get the results (or
      exceptions!) of the original Futures (or coroutines), in the order
      in which and as soon as they complete.
  
      This differs from PEP 3148; the proper way to use this is:
  
          for f in as_completed(fs):
              result = await f  # The 'await' may raise.
              # Use result.
  
      If a timeout is specified, the 'await' will raise
      TimeoutError when the timeout occurs before all Futures are done.
  
      Note: The futures 'f' are not necessarily members of fs.
      """
      if futures.isfuture(fs) or coroutines.iscoroutine(fs):
          raise TypeError(
              f"expect an iterable of futures, not {type(fs).__name__}"
          )
  
      from .queues import (
          Queue,
      )  # Import here to avoid circular import problem.
  
      done = Queue()
  
      loop = events.get_event_loop()
      todo = {ensure_future(f, loop=loop) for f in set(fs)}
      timeout_handle = None
  
      def _on_timeout():
          for f in todo:
              f.remove_done_callback(_on_completion)
              done.put_nowait(
                  None
              )  # Queue a dummy value for _wait_for_one().
          todo.clear()  # Can't do todo.remove(f) in the loop.
  
      def _on_completion(f):
          if not todo:
              return  # _on_timeout() was here first.
          todo.remove(f)
          done.put_nowait(f)
          if not todo and timeout_handle is not None:
              timeout_handle.cancel()
  
      async def _wait_for_one():
          f = await done.get()
          if f is None:
              # Dummy value from _on_timeout().
              raise exceptions.TimeoutError
          return f.result()  # May raise f.exception().
  
      for f in todo:
          f.add_done_callback(_on_completion)
      if todo and timeout is not None:
          timeout_handle = loop.call_later(timeout, _on_timeout)
      for _ in range(len(todo)):
          yield _wait_for_one()
  
imports: import concurrent.futures
  import contextvars
  import functools
  import inspect
  import itertools
  import math
  import types
  import weakref
  from types import GenericAlias
  from .None import base_tasks
  from .None import coroutines
  from .None import events
  from .None import exceptions
  from .None import futures
  from .None import timeouts
label_desc: Use image node_id 5 for calling a global function with example usage: as_completed(fs) and returns: f