code: def as_completed(
      jobs: tp.Sequence[core.Job[core.R]],
      timeout: tp.Optional[tp.Union[int, float]] = None,
      poll_frequency: float = 10,
  ) -> tp.Iterator[core.Job[core.R]]:
      """
      Yields jobs as they complete (finished, failed or were cancelled).
      Raises a TimeoutError if the result isn’t available after timeout seconds.
      timeout can be an int or float. If timeout is not specified or None, there is no
      limit to the wait time.
  
      Parameters
      ----------
      jobs: list
          Jobs instances
  
      timeout: int/float
          Maximum time (in sec) to wait for jobs completion
  
      poll_frequency: float
          Frequency in second at which we check job status.
  
      Yields
      ------
      Job
          The next completed job
      """
      start = time.time()
      jobs_done: tp.Set[int] = set()
      while True:
          if timeout is not None and time.time() - start > timeout:
              raise TimeoutError
          for i, job in enumerate(jobs):
              if i in jobs_done:
                  continue
              if job.done():
                  jobs_done.add(i)
                  yield job
          if len(jobs_done) == len(jobs):
              break
          time.sleep(poll_frequency)
  
imports: import collections
  import contextlib
  import datetime
  import itertools
  import os
  import random
  import shutil
  import subprocess
  import tempfile
  import time
  import typing
  from pathlib import Path
  from .core import core
  from .core.job_environment import JobEnvironment
  from .core.utils import CommandFunction
  from .core.utils import DelayedSubmission
  from .core.utils import environment_variables
label_desc: Use image node_id 1 for calling a global function with example usage: as_completed(jobs, timeout, poll_frequency) without return types