'Iterate over schedule.
This iterator yields a tuple of ``(entry, wait_seconds)``,
where if entry is :const:`None` the caller should wait
for ``wait_seconds`` until it polls the schedule again.'

def __iter__(self, min=min, nowfun=monotonic, pop=heapq.heappop, push=heapq.heappush):

    max_interval = self.max_interval
    queue = self._queue
    while 1:
        if queue:
            eventA = queue[0]
            (now, eta) = (nowfun(), eventA[0])
            if (now < eta):
                (yield (min((eta - now), max_interval), None))
            else:
                eventB = pop(queue)
                if (eventB is eventA):
                    entry = eventA[2]
                    if (not entry.canceled):
                        (yield (None, entry))
                    continue
                else:
                    push(queue, eventB)
        else:
            (yield (None, None))
