Pop the next future from the queue;
        in progress futures have priority over those that have not yet started;
        higher level futures have priority over lower level ones;
962223
def pop(self):
        
        self.updateQueue()

        # If our buffer is underflowing, request more Futures
        if self.timelen(self) < self.lowwatermark:
            self.requestFuture()

        # If an unmovable Future is ready to be executed, return it
        if len(self.ready) != 0:
            return self.ready.popleft()

        # Then, use Futures in the movable queue
        elif len(self.movable) != 0:
            return self.movable.popleft()
        else:
            # Otherwise, block until a new task arrives
            self.lastStatus = time.time()
            while len(self) == 0:
                # Block until message arrives
                self.askForPreviousFutures()
                self.socket._poll(POLLING_TIME)
                self.updateQueue()
            if len(self.ready) != 0:
                return self.ready.popleft()
            elif len(self.movable) != 0:
                return self.movable.popleft()
316907
def _future_completed(future):
    
    exc = future.exception()
    if exc:
        log.debug("Failed to run task on executor", exc_info=exc)
601516
def add_future(self, future, callback):
        
        assert is_future(future)
        callback = stack_context.wrap(callback)
        future.add_done_callback(
            lambda future: self.add_callback(callback, future))
247688
@Override
    // thanks to
    // http://binkley.blogspot.fr/2009/04/jumping-work-queue-in-executor.html
    // for backward compat to SDK 8 (JDK 5)
    protected <T> RunnableFuture<T> newTaskFor(Runnable runnable, T value) {
        // makes findbugs happy, there must be some @Nullable
        // annotation in JDK..
        if (runnable == null) {
            return null;
        }
        return new PriorityFuture<T>(runnable, ((PriorityRunnable) runnable).getPriority(), value);
    }
851530
private Queue<ReadFuture> getReadyReadFutures() {
        Queue<ReadFuture> readyReadFutures =
            (Queue<ReadFuture>) getAttribute(READY_READ_FUTURES_KEY);
        if (readyReadFutures == null) {
            readyReadFutures = new CircularQueue<>();

            Queue<ReadFuture> oldReadyReadFutures =
                (Queue<ReadFuture>) setAttributeIfAbsent(
                        READY_READ_FUTURES_KEY, readyReadFutures);
            if (oldReadyReadFutures != null) {
                readyReadFutures = oldReadyReadFutures;
            }
        }
        return readyReadFutures;
    }
420040
def next(self):
        
        if self.blocking >= 0:
            # returns queue name and item, we just need item
            res = self.redis.blpop([self.name], timeout=self.blocking)
            if res:
                res = res[1]
        else:
            res = self.redis.lpop(self.name)
        value = self.deserialize(res)
        logger.debug('Popped from "%s": %s', self.name, repr(value))
        return value
498980
private void completeFutures() {
    long commitIndex = queues.values().stream()
        .map(queue -> queue.ackedIndex)
        .reduce(Math::min)
        .orElse(0L);
    for (long i = context.getCommitIndex() + 1; i <= commitIndex; i++) {
      CompletableFuture<Void> future = futures.remove(i);
      if (future != null) {
        future.complete(null);
      }
    }
    context.setCommitIndex(commitIndex);
  }
719989
function FutureJoin(first) {
        Future.call(this);

        this.first = first;
        this.missing = first instanceof Future && first.state === STATE_LISTEN ? 1 : 0;
    }
53522
def append(self, future):
        
        future.prev = self.tail
        if self.tail is None:
            assert self.head is None
            self.head = future
        else:
            self.tail.next = future
        self.tail = future
        # Once done, it will be removed from the list.
        future.add_done_callback(self.remove)
804446
def maybe_get_next_message(self):
        
        if self.pending:
            self.ioloop.add_callback(
                self.invoke_consumer, self.pending.popleft())
245734
def and_raise_future(self, exception):
        
        future = _get_future()
        future.set_exception(exception)
        return self.and_return(future)
41742
private Queue<ReadFuture> getWaitingReadFutures() {
        Queue<ReadFuture> waitingReadyReadFutures =
            (Queue<ReadFuture>) getAttribute(WAITING_READ_FUTURES_KEY);
        if (waitingReadyReadFutures == null) {
            waitingReadyReadFutures = new CircularQueue<>();

            Queue<ReadFuture> oldWaitingReadyReadFutures =
                (Queue<ReadFuture>) setAttributeIfAbsent(
                        WAITING_READ_FUTURES_KEY, waitingReadyReadFutures);
            if (oldWaitingReadyReadFutures != null) {
                waitingReadyReadFutures = oldWaitingReadyReadFutures;
            }
        }
        return waitingReadyReadFutures;
    }
704229
def _maybe_clear_confirmation_futures(self):
        
        for name in self._connections.keys():
            self._connections[name].clear_confirmation_futures()
317590
public void advance() {
        String s = null;
        if (baseIterator.hasNext())
            next = baseIterator.next();
        else
            next = null;
    }
66605
def _future_done(self, future):
        
        try:
            # notify the subscribers (except result is an exception or NONE)
            result = future.result()  # may raise exception
            if result is not NONE:
                self.notify(result)  # may also raise exception
        except asyncio.CancelledError:
            return
        except Exception:  # pylint: disable=broad-except
            self._options.error_callback(*sys.exc_info())

        # check if queue is present and something is in the queue
        if self._queue:
            value = self._queue.popleft()

            # start the coroutine
            self._run_coro(value)
        else:
            self._future = None
1090112
def _next_job(self):
        """"""
        if self.__job_queue:
            # Produce message from the top of the queue
            job = self.__job_queue.pop()
            # logging.debug("queue = %s, popped %r", self.__job_queue, job)
            job.process()
246516
private void advance() {
        next = null;

        // While the underlying iterator has paths, check whether any are
        // accepted by the filter.
        while (iterator.hasNext() && next == null) {
            DependencyPath p = iterator.next();
            if (acceptor.accepts(p)) 
                next = p;
        }        
    }