Waits for ListenableFuture to terminate. Cancels on timeout
770207
protected <V> V awaitResult(ListenableFuture<V> future) {
    return awaitResult(future, timeout, TimeUnit.MILLISECONDS);
  }
37613
def cancel(self):
        
        super(MapFuture, self).cancel()

        return any(tuple(f.cancel() for f in self._futures))
830724
protected void waitForCommand(ITimerCallback callback, long timeout) throws WidgetTimeoutException {
		WaitForConditionTimer t = new WaitForConditionTimer(getByLocator(), callback);
		t.waitUntil(timeout);
	}
158195
function wait(testCallback, waitCallback) {
          if (!testCallback()) {
            // Wait for timeout
            if ((new Date().getTime()) - startTime < maxLoadTime) {
              Delay.setTimeout(waitCallback);
            } else {
              failed();
            }
          }
        }
1086518
def wait(self, timeout=None):
        

        if timeout is not None:
            if not self._thread:
                self._thread = threading.Thread(target=self._wait4process)
                self._thread.daemon = 1
                self._thread.start()

        if self._thread:
            self._thread.join(timeout=timeout)
            self.timeout_happened = self.timeout_happened or self._thread.isAlive()
        else:
            # no timeout and no existing thread
            self._wait4process()

        return self
563151
@Override
    public void awaitNanos(final long timeout) throws InterruptedException {
        long remaining = timeout;
        queueLock.lock();
        try {
            while(test() && remaining > 0) {
                remaining = condition.awaitNanos(remaining);
            }
        }
        finally {
            queueLock.unlock();
        }
    }
1049042
private static <V> ListenableFuture<V> closedChannelFuture() {
    SettableFuture<V> future = SettableFuture.create();
    future.setException(new ClosedChannelException());
    return future;
  }
560849
protected void awaitForPushToFinish(Future<?> future, long timeout, TimeUnit unit) {
      final boolean debugEnabled = log.isDebugEnabled();
      try {
         if (debugEnabled) log.debug("wait for state push to cache loader to finish");
         future.get(timeout, unit);
      } catch (TimeoutException e) {
         if (debugEnabled) log.debug("timed out waiting for state push to cache loader to finish");
      } catch (ExecutionException e) {
         if (debugEnabled) log.debug("exception reported waiting for state push to cache loader to finish");
      } catch (InterruptedException ie) {
         /* Re-assert the thread's interrupted status */
         Thread.currentThread().interrupt();
         if (trace) log.trace("wait for state push to cache loader to finish was interrupted");
      }
   }
653659
public void waitFor(long timeout) throws JSchException, ExitCode, InterruptedException {
        long deadline;

        try {
            deadline = System.currentTimeMillis() + timeout;
            while (!channel.isClosed()) {
                if (System.currentTimeMillis() >= deadline) {
                    throw new TimeoutException(this);
                }
                Thread.sleep(100); // throws InterruptedException
            }
            if (channel.getExitStatus() != 0) {
                throw new ExitCode(new Launcher(command), channel.getExitStatus());
            }
        } finally {
            channel.disconnect();
        }
    }
1090943
def until_any(*futures, **kwargs):
    
    timeout = kwargs.get('timeout', None)
    ioloop = kwargs.get('ioloop', None) or tornado.ioloop.IOLoop.current()
    any_future = tornado_Future()

    def handle_done(done_future):
        if not any_future.done():
            try:
                any_future.set_result(done_future.result())
            except Exception:
                any_future.set_exc_info(done_future.exc_info())
            # (NM) Nasty hack to remove handle_done from the callback list to prevent a
            # memory leak where one of the futures resolves quickly, particularly when
            # used together with AsyncState.until_state(). Also addresses Jira issue
            # CM-593
            for f in futures:
                if f._callbacks:
                    try:
                        f._callbacks.remove(handle_done)
                    except ValueError:
                        pass

    for f in futures:
        f.add_done_callback(handle_done)
        if any_future.done():
            break

    if timeout:
        return with_timeout(ioloop.time() + timeout, any_future, ioloop)
    else:
        return any_future
435148
function (canceller) {
        var self = this;
        this._canceller = canceller;
        this._timeout = null;
        this._timer = null;

        this.handled = false;

        this.waiting = [];
        this.result = undefined;
        this.isError = false;
        this.finished = false;

        //this.currentContextHandler = contextHandler.getHandler && contextHandler.getHandler();
        this.__defineGetter__('promise', this.getPromise);
    }
357570
def wait_stop(self):
        
        if not self.running:
            return
        self.stop()
        try:
            yield from self._task
        except asyncio.CancelledError:
            pass
918634
public NotifyingFuture<V> poll(long timeout, TimeUnit unit) throws InterruptedException {
        return completionQueue.poll(timeout, unit);
    }
925531
def wait(self):
        

        while True:
            if not self.greenlet_watch:
                break

            if self.stopping:
                gevent.sleep(0.1)
            else:
                gevent.sleep(1)
235898
private synchronized void waitForPush() {
        long waitStart = -1L;
        
        while( waiting != null && waiting.isEmpty() && !loaded ) {
            long untouched = System.currentTimeMillis() - lastTouch;
            
            if( untouched > timeout.longValue() ) {
                logger.error("[" + this + "] Jiterator timeout for " + getName());
                setLoadException(new TimeoutException("Jiterator " + getName() + " timed out while loading"));
            }
            if( waitStart == -1L ) {
                waitStart = System.currentTimeMillis();
            }
            else {
                if( (System.currentTimeMillis() - waitStart) > CalendarWrapper.MINUTE ) {
                    if( (System.currentTimeMillis() - scream) > CalendarWrapper.MINUTE ) {
                        scream = System.currentTimeMillis();
                        logger.warn("[" + this + "] " + ((System.currentTimeMillis()-lastTouch)/1000) + " seconds since last touch.");
                    }
                }
            }
            long multiplier = (untouched/(15 * CalendarWrapper.SECOND)) + 1;

            try { wait(150L * multiplier); }
            catch( InterruptedException ignore ) { }
        }        
    }
598856
public void waitForState(State state, Timespan timeout)
    throws TimeoutException, InterruptedException
  {
    long endTime = timeout == null ? 0 : timeout.futureTimeMillis(_clock);

    synchronized(_lock)
    {
      while(_state != state)
      {
        ConcurrentUtils.awaitUntil(_clock, _lock, endTime);
      }
    }
  }
458678
public void await(Event event, long timeout, TimeUnit unit) throws InterruptedException, TimeoutException {
        long timestamp = getTimestamp(event);
        try {
            lock.lockInterruptibly();
            single(timestamp);
            while (isPermit(event, timestamp) == false) {
                condition.await(timeout, unit);
            }
        } finally {
            lock.unlock();
        }
    }