code: def gen_retries(start, end, intervals, time=time):
      
      for interval in intervals:
          now = time()
          if now < end:
              wait = min(interval, end - now)
              yield now - start, end - now, wait
          else:
              yield now - start, end - now, 0
              break
docs: Helper for retrying something, sleeping between attempts.
  
      Yields ``(elapsed, remaining, wait)`` tuples, giving times in seconds. The
      last item, `wait`, is the suggested amount of time to sleep before trying
      again.
  
      This function works in concert with `retries`. It's split out so that
      `retries` can capture the correct start time rather than the time at which
      it is first iterated.
  
      :param start: The start time, in seconds, of this generator. This must be
          congruent with the `IReactorTime` argument passed to this generator.
      :param end: The desired end time, in seconds, of this generator. This must
          be congruent with the `IReactorTime` argument passed to this
          generator.
      :param intervals: A iterable of intervals, each in seconds, which should
          be used as hints for the `wait` value that's generated.
      :param time: A callable that returns the current time in seconds.