Wake up the first waiter who isn't cancelled.
964060
def _wake_up_first(self):
        """"""
        for fut in self._waiters:
            if not fut.done():
                fut.set_result(True)
                break
767509
def cancel(self):
        """"""
        if self in scoop._control.execQueue.movable:
            self.exceptionValue = CancelledError()
            scoop._control.futureDict[self.id]._delete()
            scoop._control.execQueue.remove(self)
            return True
        return False
713629
def wait(self):
        
        d = defer.Deferred()
        if self._result is None:
            self._waiters.append(d)
        else:
            self._fire_deferred(d)
        return d
23033
private void onBegin()
   {
      Queue<Long> q = currentTime.get();
      q.add(System.currentTimeMillis());
   }
277327
def _clear_done_waiters(self):
        """"""
        while self._waiters and self._waiters[0].done():
            self._waiters.popleft()
        if not self._waiters:
            self._stop_listening()
221878
def start(self):
        
        # While the implemetation matches the description in the docstring
        # conceptually, it always adds a new waiter and then calls
        # _check_concurrent() to handle the various cases.
        if self._limit < 0:
            # Special case for no limit, never block.
            return succeed(None)
        elif self._limit == 0:
            # Special case for limit of zero, always block forever.
            return Deferred()
        d = self._make_waiter()
        self._check_concurrent()
        return d
1193961
def set(self):
        
        self._is_set = True
        scheduler.state.awoken_from_events.update(self._waiters)
        del self._waiters[:]
770820
def release(self):
        """"""
        #  This decrements the appropriate lock counters, and if the lock
        #  becomes free, it looks for a queued thread to hand it off to.
        #  By doing the handoff here we ensure fairness.
        me = currentThread()
        with self._lock:
            if self.is_exclusive:
                if self._exclusive_owner is not me:
                    raise RuntimeError("release() called on unheld lock")
                self.is_exclusive -= 1
                if not self.is_exclusive:
                    self._exclusive_owner = None
                    #  If there are waiting shared locks, issue it to them
                    #  all and then wake everyone up.
                    if self._shared_queue:
                        for (thread,waiter) in self._shared_queue:
                            self.is_shared += 1
                            self._shared_owners[thread] = 1
                            waiter.notify()
                        del self._shared_queue[:]
                    #  Otherwise, if there are waiting exclusive locks,
                    #  they get first dibbs on the lock.
                    elif self._exclusive_queue:
                        (thread,waiter) = self._exclusive_queue.pop(0)
                        self._exclusive_owner = thread
                        self.is_exclusive += 1
                        waiter.notify()
            elif self.is_shared:
                try:
                    self._shared_owners[me] -= 1
                    if self._shared_owners[me] == 0:
                        del self._shared_owners[me]
                except KeyError:
                    raise RuntimeError("release() called on unheld lock")
                self.is_shared -= 1
                if not self.is_shared:
                    #  If there are waiting exclusive locks,
                    #  they get first dibbs on the lock.
                    if self._exclusive_queue:
                        (thread,waiter) = self._exclusive_queue.pop(0)
                        self._exclusive_owner = thread
                        self.is_exclusive += 1
                        waiter.notify()
                    else:
                        assert not self._shared_queue
            else:
                raise RuntimeError("release() called on unheld lock")
1057530
def start(self, initial_delay=0):
        
        if self.listener is None:
            raise exceptions.NoAsyncListenerError
        elif self._enabled:
            return

        self._enabled = True
642512
def wait(self):
        """"""
        now = _monotonic()
        if now < self._ref:
            delay = max(0, self._ref - now)
            self.sleep_func(delay)
        self._update_ref()
534004
private function cancelPending()
    {
        if (!$this->busyQueue->isEmpty()) {
            $exception = new WorkerException('Worker was shut down.');

            do {
                $this->busyQueue->dequeue()->cancel($exception);
            } while (!$this->busyQueue->isEmpty());
        }
    }
169856
def resume(self):
        """"""
        with self._wake:
            self._paused = False
            self._wake.notifyAll()
366760
def force_close(self) -> None:
        """"""
        self._force_close = True
        if self._waiter:
            self._waiter.cancel()
        if self.transport is not None:
            self.transport.close()
            self.transport = None
46118
def wait(self, until=0):
        
        if self._count != until:
            self._waiters.setdefault(until, []).append(compat.getcurrent())
            scheduler.state.mainloop.switch()
356285
def wait_until_finished(self):
        """"""
        try:
            self.thread.join()
        except KeyboardInterrupt:
            self._logger.debug('Keyboard interrupt detected, stopping driver.')
            self._active = False
            self._wake_queue()
612831
def sleep(self):
        """"""

        if self.next_time and time.time() < self.next_time:
            time.sleep(self.next_time - time.time())
470032
def cancel(self):
        
        try:
            self.post("control", action="cancel")
        except HTTPError as he:
            if he.status == 404:
                # The job has already been cancelled, so
                # cancelling it twice is a nop.
                pass
            else:
                raise
        return self