retrieve latency, then wait 1 sec
164079
function getLatencyAndWait() {
      var result = null;

      if (isDestroyed) {
        return Promise.resolve(result);
      }

      return getLatency(slave)
          .then(function (latency) { result = latency })  // store the retrieved latency
          .catch(function (err)    { console.log(err) })  // just log failed requests
          .then(function () { return util.wait(DELAY) })  // wait 1 sec
          .then(function () { return result});            // return the retrieved latency
    }
518095
def wait(self, seconds, poll_interval):
        
        # jid is None when all hosts were skipped
        if self.jid is None:
            return self.results

        clock = seconds - poll_interval
        while (clock >= 0 and not self.completed):
            time.sleep(poll_interval)

            poll_results = self.poll()

            for (host, res) in poll_results['polled'].iteritems():
                if res.get('started'):
                    self.runner.callbacks.on_async_poll(host, res, self.jid, clock)

            clock = clock - poll_interval

        return self.results
240775
def wait_for_net(self, timeout=None, wait_polling_interval=None):
        
        if timeout is None:
            timeout = self._timeout
        if wait_polling_interval is None:
            wait_polling_interval = self._wait_polling_interval

        self._logger.info("Waiting for network connection")
        poll_wait(self.get_ip_address, timeout=timeout)
1119532
function addLatency(request, response, next) {
	if (request.path === '/') {
		return next();
	}
	setTimeout(next, args.latency);
}
1181639
function getLatency(emitter) {
    var start = Date.now();

    return emitter.request('time')
        .then(function (timestamp) {
          var end = Date.now();
          var latency = (end - start) / 2;
          var time = timestamp + latency;

          // apply the first ever retrieved offset immediately.
          if (isFirst) {
            isFirst = false;
            emitter.emit('change', time);
          }

          return latency;
        })
  }
402247
def _reconnect_delay(self):
        
        if self.RECONNECT_ON_ERROR and self.RECONNECT_DELAYED:
            if self._reconnect_attempts >= len(self.RECONNECT_DELAYS):
                return self.RECONNECT_DELAYS[-1]
            else:
                return self.RECONNECT_DELAYS[self._reconnect_attempts]
        else:
            return 0
1062471
def wait_for_net_service(server, port, timeout=None, poll_interval=0.1):
    
    import socket
    import errno

    s = socket.socket()
    if timeout:
        from time import time as now
        # time module is needed to calc timeout shared between two exceptions
        end = now() + timeout

    while True:
        try:
            if timeout:
                next_timeout = end - now()
                if next_timeout < 0:
                    return False
                else:
                    s.settimeout(next_timeout)

            s.connect((server, port))

        except socket.timeout as err:
            # this exception occurs only if timeout is set
            if timeout:
                return False

        except Exception as err:
            # catch timeout exception from underlying network library
            # this one is different from socket.timeout
            if not isinstance(err.args, tuple) or err.args[0] != errno.ETIMEDOUT:
                pass  # raise
        else:
            s.close()
            return True
        time.sleep(poll_interval)
1031528
def latency(self):
        
        with self.lock:
            self.send('PING %s' % self.server)
            ctime = self._m_time.time()

            msg = self._recv(expected_replies=('PONG',))
            if msg[0] == 'PONG':
                latency = self._m_time.time() - ctime
                return latency
135681
def wait_socket(host, port, timeout=120):
    '''
    
    '''
    return wait_result(lambda: check_socket(host, port), True, timeout)
1248549
def recv(self, timeout=-1):
        
        if self.ready:
            return self.other.handover(self)

        return self.pause(timeout=timeout)
402827
private Object waitingGet(boolean interruptible) {
        Signaller q = null;
        boolean queued = false;
        int spins = SPINS;
        Object r;
        while ((r = result) == null) {
            if (spins > 0) {
                if (ThreadLocalRandom.nextSecondarySeed() >= 0)
                    --spins;
            }
            else if (q == null)
                q = new Signaller(interruptible, 0L, 0L);
            else if (!queued)
                queued = tryPushStack(q);
            else {
                try {
                    ForkJoinPool.managedBlock(q);
                } catch (InterruptedException ie) { // currently cannot happen
                    q.interrupted = true;
                }
                if (q.interrupted && interruptible)
                    break;
            }
        }
        if (q != null) {
            q.thread = null;
            if (q.interrupted) {
                if (interruptible)
                    cleanStack();
                else
                    Thread.currentThread().interrupt();
            }
        }
        if (r != null)
            postComplete();
        return r;
    }
163089
def _wait_for_request(self, uuid, connection_adapter=None):
        
        start_time = time.time()
        while not self._response[uuid]:
            connection_adapter.check_for_errors()
            if time.time() - start_time > self._timeout:
                self._raise_rpc_timeout_error(uuid)
            time.sleep(IDLE_WAIT)
546742
def _get_slave_timeout(self, dpid, port):
        """"""
        slave = self._get_slave(dpid, port)
        if slave:
            return slave['timeout']
        else:
            return 0
157692
def receive_one_ping(mySocket, myID, timeout):
    
    timeLeft = timeout/1000

    while True: # Loop while waiting for packet or timeout
        startedSelect = default_timer()
        whatReady = select.select([mySocket], [], [], timeLeft)
        howLongInSelect = (default_timer() - startedSelect)
        if whatReady[0] == []: # Timeout
            return None, 0, 0, 0, 0

        timeReceived = default_timer()

        recPacket, addr = mySocket.recvfrom(ICMP_MAX_RECV)

        ipHeader = recPacket[:20]
        iphVersion, iphTypeOfSvc, iphLength, \
        iphID, iphFlags, iphTTL, iphProtocol, \
        iphChecksum, iphSrcIP, iphDestIP = struct.unpack(
            "!BBHHHBBHII", ipHeader
        )

        icmpHeader = recPacket[20:28]
        icmpType, icmpCode, icmpChecksum, \
        icmpPacketID, icmpSeqNumber = struct.unpack(
            "!BBHHH", icmpHeader
        )

        if icmpPacketID == myID: # Our packet
            dataSize = len(recPacket) - 28
            #print (len(recPacket.encode()))
            return timeReceived, (dataSize+8), iphSrcIP, icmpSeqNumber, iphTTL

        timeLeft = timeLeft - howLongInSelect
        if timeLeft <= 0:
            return None, 0, 0, 0, 0
643008
def get(self, timeout=None):
        
        if not self.wait(timeout):
            raise TimeoutError("Result not available within %fs" % timeout)
        if self._success:
            return self._data
        raise self._data[0]
1150453
def get_delay
      return @retry_timeout unless @retry_timeout.nil?

      if !response.nil? && !response.headers['Retry-After'].nil?
        return response.headers['Retry-After'].to_i
      end

      return AsyncOperationStatus::DEFAULT_DELAY
    end
921669
public void get(long timeout, TimeUnit unit) throws InterruptedException, TimeoutException {
        sync.innerGet(unit.toNanos(timeout));
    }