/*
Instruments request for timeouts
771660
function instrumentReq(config, req, resp) {
    var closer,
        timeout;

    config.idle_timeout = parseInt(config.idle_timeout, 10);
    if (config.idle_timeout > 0) {
        if (req.socket) {
            req.socket.setTimeout(config.idle_timeout);
        } else if (req.connection && req.connection.socket) {
            req.connection.socket.setTimeout(config.idle_timeout);
        }
    }

    config.inc_req_timeout = parseInt(config.inc_req_timeout, 10);
    // "incoming_timeout" deprecated, since it was never documented
    config.incoming_timeout = parseInt(config.incoming_timeout, 10);
    // sets the timeout on the request
    timeout = config.inc_req_timeout || config.incoming_timeout || globalIncoming;
    if (timeout) {
        closer = new Closer(resp, timeout);
        resp.on('finish', function() {
            closer.remove();
        });
        resp.on('close', function() {
            closer.remove();
        });
    }
}
1022474
function onClientTimeoutPostRequestHandler (ctx, err) {
  if (err) {
    let error = null;
    if (err instanceof SuperError) {
      error = err.rootCause || err.cause || err;
    } else {
      error = err;
    }

    let internalError = new Errors.MostlyError(Constants.EXTENSION_ERROR).causedBy(err);
    ctx.log.error(internalError);

    ctx._response.error = error;
    ctx.emit('clientResponseError', error);
  }

  try {
    ctx._execute(ctx._response.error);
  } catch(err) {
    let error = null;
    if (err instanceof SuperError) {
      error = err.rootCause || err.cause || err;
    } else {
      error = err;
    }

    let internalError = new Errors.FatalError(Constants.FATAL_ERROR, ctx.errorDetails).causedBy(err);
    ctx.log.fatal(internalError);

    ctx.emit('clientResponseError', error);

    // let it crash
    if (ctx._config.crashOnFatal) {
      ctx.fatal();
    }
  }
}
915472
def timeout(timeout_time, default):
        '''
        
        '''
        def timeout_function(f):
            def f2(*args):
                def timeout_handler(signum, frame):
                    raise MethodTimer.DecoratorTimeout()

                old_handler = signal.signal(signal.SIGALRM, timeout_handler)
                # triger alarm in timeout_time seconds
                signal.alarm(timeout_time)
                try:
                    retval = f(*args)
                except MethodTimer.DecoratorTimeout:
                    return default
                finally:
                    signal.signal(signal.SIGALRM, old_handler)
                signal.alarm(0)
                return retval
            return f2
        return timeout_function
603132
protected void unregisterAllTimeouts() {
		for (Timeout<K> timeout : timeouts.values()) {
			timeout.cancel();
		}
		timeouts.clear();
	}
364815
@When("^in less than '(\\d+?)' seconds, checking each '(\\d+?)' seconds, I send a '(.+?)' request to '(.+?)'( so that the response( does not)? contains '(.+?)')?$")
    public void sendRequestTimeout(Integer timeout, Integer wait, String requestType, String endPoint, String foo, String contains, String responseVal) throws Exception {

        AssertionError ex = null;
        String type = "";
        Future<Response> response;

        if (foo != null) {
            Boolean searchUntilContains;
            if (contains == null || contains.isEmpty()) {
                searchUntilContains = Boolean.TRUE;
            } else {
                searchUntilContains = Boolean.FALSE;
            }
            Boolean found = !searchUntilContains;

            Pattern pattern = CommonG.matchesOrContains(responseVal);
            for (int i = 0; (i <= timeout); i += wait) {
                if (found && searchUntilContains) {
                    break;
                }
                response = commonspec.generateRequest(requestType, false, null, null, endPoint, "", type, "");
                commonspec.setResponse(requestType, response.get());
                commonspec.getLogger().debug("Checking response value");
                try {
                    if (searchUntilContains) {
                        assertThat(commonspec.getResponse().getResponse()).containsPattern(pattern);
                        found = true;
                        timeout = i;
                    } else {
                        assertThat(commonspec.getResponse().getResponse()).doesNotContain(responseVal);
                        found = false;
                        timeout = i;
                    }
                } catch (AssertionError e) {
                    if (!found) {
                        commonspec.getLogger().info("Response value not found after " + i + " seconds");
                    } else {
                        commonspec.getLogger().info("Response value found after " + i + " seconds");
                    }
                    Thread.sleep(wait * 1000);
                    ex = e;
                }
                if (!found && !searchUntilContains) {
                    break;
                }
            }
            if ((!found && searchUntilContains) || (found && !searchUntilContains)) {
                throw (ex);
            }
            if (searchUntilContains) {
                commonspec.getLogger().info("Success! Response value found after " + timeout + " seconds");
            } else {
                commonspec.getLogger().info("Success! Response value not found after " + timeout + " seconds");
            }
        } else {

            for (int i = 0; (i <= timeout); i += wait) {
                response = commonspec.generateRequest(requestType, false, null, null, endPoint, "", type, "");
                commonspec.setResponse(requestType, response.get());
                commonspec.getLogger().debug("Checking response value");
                try {
                    assertThat(commonspec.getResponse().getResponse());
                    timeout = i;
                } catch (AssertionError e) {
                    Thread.sleep(wait * 1000);
                    ex = e;
                }
            }
        }
    }
412787
function instrumentFunction( func, entry ) {
   return ( ...args ) => {
      const start = win.performance.now();
      const result = func( ...args );
      const time = win.performance.now() - start;

      ++entry.count;
      entry.time += time;

      return result;
   };
}
1354660
public void getInstrumentsForExchange(KiteConnect kiteConnect) throws KiteException, IOException {
        // Get instruments for an exchange.
        List<Instrument> nseInstruments = kiteConnect.getInstruments("CDS");
        System.out.println(nseInstruments.size());
    }
163194
@Override
    protected void checkForTimeouts() {
        // See if anything may have timed out
        if (currentTime < nextTimeoutTime) {
            return;
        }
        Set<SelectionKey> selectorKeys = selector.keys();
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(this, tc, "checkForTimeouts - checking " + selectorKeys.size() + " keys for timeouts");
        }
        if (selectorKeys.isEmpty()) {
            // if this isn't the primary (first) selector, see if it should be closed
            if (countIndex != 0) {
                // if we have already been waiting, and still no keys, and this isn't
                // the primary
                // selector, we should close this selector/thread
                if (waitingToQuit) {
                    quit = true;
                } else {
                    wqm.updateCount(countIndex, WorkQueueManager.CS_DELETE_IN_PROGRESS, channelType);
                    waitingToQuit = true;
                    nextTimeoutTime = currentTime + TCPFactoryConfiguration.getChannelSelectorWaitToTerminate();

                }
            } else {
                nextTimeoutTime = currentTime + TCPFactoryConfiguration.getChannelSelectorIdleTimeout();
            }
        } else {
            waitingToQuit = false;
            // go through requests, timing out those that need it, and calculating new
            // timeout
            // set nexttimeouttime to whatever the selectoridletimeout is, and work
            // back from there
            nextTimeoutTime = currentTime + TCPFactoryConfiguration.getChannelSelectorIdleTimeout();

            for (SelectionKey key : selectorKeys) {
                try {
                    if (0 == key.interestOps()) {
                        // not active
                        continue;
                    }
                    // only consider keys that are currently waiting for connect
                    ConnectInfo ci = (ConnectInfo) key.attachment();

                    if (ci.timeout != TCPConnectRequestContext.NO_TIMEOUT) {
                        if (ci.nextTimeoutTime <= currentTime) {
                            if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) {
                                Tr.event(this, tc, "Inactivity timeout on connect operation for channel" + ci.ioSocket.getChannel());
                            }

                            // create timeout exception to pass to callback error method
                            // Add local and remote address information
                            InetSocketAddress iaRemote = ci.remoteAddress;
                            InetSocketAddress iaLocal = ci.localAddress;
                            IOException e = new SocketTimeoutException("Socket operation timed out before it could be completed. local=" + iaLocal + " remote=" + iaRemote);

                            // Hand off to another thread
                            ci.setError(e);
                            if (wqm.dispatchConnect(ci)) {
                                // unable to dispatch error, handle now
                                key.cancel();
                                ci.ioSocket.close();
                            }
                        } else {
                            // see if we should timeout sooner than our current setting
                            if (ci.nextTimeoutTime < nextTimeoutTime) {
                                nextTimeoutTime = ci.nextTimeoutTime;
                            }
                        }
                    }
                } catch (CancelledKeyException cke) {
                    // either we didn't get the key, or we already dispatched the
                    // error. In either case, there is nothing more to do
                    continue;
                }
            }
        }
    }
218862
@Override
  public void setRequestTimeout(BindingProvider bindingProvider, int timeout) {
    // Production App Engine
    bindingProvider.getRequestContext().put(PRODUCTION_REQUEST_TIMEOUT_KEY, timeout);
    // Dev App Engine
    bindingProvider.getRequestContext().put(DEVEL_REQUEST_TIMEOUT_KEY, timeout);
  }
463553
@Override
	public void notifyTimeout(AllocationID key, UUID ticket) {
		checkInit();

		if (slotActions != null) {
			slotActions.timeoutSlot(key, ticket);
		}
	}
1116792
function ConnectionTimeoutError(timeout) {
    Error.call(this);
    Error.captureStackTrace(this, this.constructor);
    this.message = 'connection timed out';

    if (timeout) {
        this.message += '. timeout = ' + timeout + ' ms';
    }

    this.name = 'ConnectionTimeoutError';
}
172339
function(server, sock) {
  if (server.requestTimeouts.length === 0) {
    // nothing active
    server.timeoutSet = false;
    return;
  }

  // some requests outstanding, check if any have timed-out
  var now = timestamp();
  var soonestTimeout = server.requestTimeouts[0];

  if (soonestTimeout <= now) {
    // timeout occurred!
    sock.end();
    server.connected = false;
    server._socket = undefined;
    server.timeoutSet = false;
    server.error(new Error('socket timed out waiting on response.'));
  } else {
    // no timeout! Setup next one.
    var deadline = soonestTimeout - now;
    sock.setTimeout(deadline, function() {
      timeoutHandler(server, sock);
    });
  }
}
988013
public ConverterServerBuilder requestTimeout(long timeout, TimeUnit unit) {
        assertNumericArgument(timeout, true);
        this.requestTimeout = unit.toMillis(timeout);
        return this;
    }
1266265
function (tmr, timeout) {
    return new Promise((resolve, reject) => {
        /*eslint-disable no-return-assign */
        return tmr = setTimeout(reject, timeout, httpError(408));
    });
}
717382
def _add_timeout(self, request, future):
        """"""
        io_loop = IOLoop.current()
        t = io_loop.call_later(
            request.ttl,
            self._request_timed_out,
            request.id,
            request.service,
            request.ttl,
            future,
        )
        io_loop.add_future(future, lambda f: io_loop.remove_timeout(t))
1084425
function timeout(message) {
    $log.warn('Plugin client request timeout: ' + serialize(message));

    var promiseIndex = lodash.findIndex(promises, function(promise) {
      return promise.id == message.header.id;
    });

    if (promiseIndex >= 0) {
      var promise = lodash.pullAt(promises, promiseIndex);

      message.response = {
        statusCode: 408,
        statusText: 'REQUEST_TIMED_OUT',
        data: {
          message: 'Request timed out.'
        }
      }
      promise[0].onComplete(message);
    } else {
      $log.warn('Message request timed out but there is no promise to fulfill: ' + serialize(message));
    }
  }
118909
function () {
            clearTimeout(_timer);

            _timer = setTimeout(function () {
                var query   = null,
                    qIndex  = _queryID - 1,
                    qLength = qIndex,
                    match   = false;

                if (qIndex >= 0) {
                    _setFeature();

                    do {
                        query = _queries[qLength - qIndex];

                        if (query) {
                            match = _matches(query.mql.media);

                            if ((match && !query.mql.matches) || (!match && query.mql.matches)) {
                                query.mql.matches = match;

                                if (query.listeners) {
                                    for (var i = 0, il = query.listeners.length; i < il; i++) {
                                        if (query.listeners[i]) {
                                            query.listeners[i].call(win, query.mql);
                                        }
                                    }
                                }
                            }
                        }
                    } while(qIndex--);
                }


            }, 10);
        }