We handle tracking timeouts with an array of deadlines (requestTimeouts), as node doesn't like us setting up lots of timers, and using just one is more efficient anyway.
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);
    });
  }
}
799334
function(myFilter, count, timeOut) {
    timeOut = timeOut ? timeOut : 30000;
    var promise = new Promise(function(resolve, reject) {
      count = (typeof count !== "undefined") ? count : 1;
      var results = [];
      var toClear = setTimeout(function() {
        myFilter.stopWatching();
        reject(new Error("Timed out"));
      }, timeOut);
      myFilter.watch(function(error, result) {
        if (error) {
          clearTimeout(toClear);
          reject(error);
        } else {
          count--;
          results.push(result);
        }
        if (count <= 0) {
          clearTimeout(toClear);
          myFilter.stopWatching();
          resolve(results);
        }
      });
    });
    if (count == 0) {
      promise = promise
        .then(function(events) {
          throw "Expected to have no event";
        })
        .catch(function(error) {
          if (error.message != "Timed out") {
            throw error;
          }
        });
    }
    return promise;
  }
8012
function t(time, done) {
  if (arguments.length === 1) {
    done = time;
    time = 2000;
  }
  var error = new Error(`Callback took too long (max: ${time})`);
  var waiting = true;

  var timeout = setTimeout(function () {
    if (!waiting) return;
    waiting = false;
    done(error);
  }, time);

  function handler() {
    if (!waiting) return;
    clearTimeout(timeout);
    waiting = false;
    done.apply(this, arguments);
  }

  return handler;
}
28317
function handleRejections (runHooks, timeout) {
    process.on('unhandledRejection', err => onUncaught(err, runHooks, timeout));
}
473258
private void timeout() {
        lock.writeLock().lock();
        try {
            //if already stopped, do nothing, otherwise check times and run the timeout task
            if (!this.stopped) {
                long now = System.nanoTime();
                long remaining = this.targetEnd - now;
                this.timedout = remaining <= FTConstants.MIN_TIMEOUT_NANO;

                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    debugTime("!Start  {0}", this.start);
                    debugTime("!Target {0}", this.targetEnd);
                    debugTime("!Now    {0}", now);
                    debugTime("!Remain {0}", remaining);
                }

                //if we really have timedout then run the timeout task
                if (this.timedout) {
                    debugRelativeTime("Timeout!");
                    this.timeoutTask.run();
                } else {
                    //this shouldn't be possible but if the timer popped too early, restart it
                    debugTime("Premature Timeout!", remaining);
                    start(this.timeoutTask, remaining);
                }
            }
        } finally {
            lock.writeLock().unlock();
        }
    }
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));
    }
  }
127718
function(keys, timeout) {
  this.isDone = false;
  this.keys = keys;
  this.expected = keys.length;
  this.count = 0;
  this.timeout = timeout;
  this.data = {};
  this.errs = [];
  this.events = {
    error: null,
    timeout: null,
    done: null,
  };
  const collector = this;
  if (this.timeout) {
    this.timer = setTimeout(() => {
      const err = new Error(COLLECT_TIMEOUT);
      collector.emit('timeout', err, collector.data);
    }, timeout);
  }
}
744219
function timeoutWith$2(due, withObservable, scheduler) {
    if (scheduler === void 0) { scheduler = async.async; }
    var absoluteTimeout = isDate_1.isDate(due);
    var waitFor = absoluteTimeout ? (+due - scheduler.now()) : Math.abs(due);
    return this.lift(new TimeoutWithOperator(waitFor, absoluteTimeout, withObservable, scheduler));
}
283846
def timeout(func):
    """"""

    @wraps(func)
    def _timeout(*args, **kwargs):
        now = time()
        deadline = kwargs.pop("deadline", None)
        seconds = kwargs.pop("timeout", None)

        if deadline is None and seconds is not None:
            deadline = now + seconds

        if deadline is not None and deadline < now:
            raise TimeExceeded("TxMongo: run time exceeded by {0}s.".format(now-deadline))

        kwargs['_deadline'] = deadline
        raw_d = func(*args, **kwargs)

        if deadline is None:
            return raw_d

        if seconds is None and deadline is not None and deadline - now > 0:
            seconds = deadline - now

        timeout_d = defer.Deferred()
        times_up = reactor.callLater(seconds, timeout_d.callback, None)

        def on_ok(result):
            if timeout_d.called:
                raw_d.cancel()
                raise TimeExceeded("TxMongo: run time of {0}s exceeded.".format(seconds))
            else:
                times_up.cancel()
                return result[0]

        def on_fail(failure):
            failure.trap(defer.FirstError)
            assert failure.value.index == 0
            times_up.cancel()
            failure.value.subFailure.raiseException()


        return defer.DeferredList([raw_d, timeout_d], fireOnOneCallback=True,
                                  fireOnOneErrback=True, consumeErrors=True).addCallbacks(on_ok, on_fail)

    return _timeout
636601
function withTimeout_p(timeoutMs, promise, label) {
  label = label || 'Operation';
  var defer = Q.defer();
  promise.then(
    function(value) {
      defer.resolve(value);
    },
    function(err) {
      defer.reject(err);
    }
  );
  setTimeout(function() {
    var err = new Error(label + ' timed out');
    err.code = 'ETIMEOUT';
    defer.reject(err);
  }, timeoutMs);
  return defer.promise;
}
1282632
public void doEvents() {
		while (!isInterrupted()) {
			Iterator<Map.Entry<Timer, Runnable>> it = timerMap.entrySet().iterator();
			if (it.hasNext()) {
				long timeout = it.next().getKey().uptime - System.currentTimeMillis();
				doEvents(timeout > 0 ? timeout : 0);
			} else {
				doEvents(-1);
			}
		}
	}
587565
function _handleTimeout(id, callback) {
                // Handle timeout
                if (id && "function" === typeof callback) {
                    try {
                        callback.call(null, new Error("Callback: Operation Timeout!"));
                    }
                    catch (ex) {
                        /* istanbul ignore next  */
                        PostMessageUtilities.log("Error while trying to handle the timeout using the callback", "ERROR", "PostMessageCourier");
                    }
                }
            }
253157
function(err, results) {

        if(options.headers) {
          // Set some headers so we can track what's going on
          var headers = {
            'X-Throttled': results.throttled,
            'X-Throttle-Remaining': Math.max(options.limit - results.count, 0)
          };
          if (results.expiresAt) {
            headers['X-Throttle-Reset'] = results.expiresAt;
          }
          res.set(headers);
        }

        if (err) {
          // Unknown error
          next(err);
          return;
        } else if (results.throttled) {

          if(logger) {
            // Log it
            logger.warn(
              '%s - ResponseThrottled for %s seconds - %s requests exceeded %s within %s seconds',
              ip,
              options.ban,
              results.count,
              options.limit,
              options.period);
          }

          // Let the client know this is forbidden
          res.status(403);

          // Create a human readable error
          var banLength = moment.duration(options.ban, 'seconds').humanize();
          next('Warning: Too many requests. You have been throttled for ' + banLength + '. ' +
            'Try again ' + moment(results.expiresAt).fromNow());
          return;
        } else {
          // All is good
          next();
          return;
        }
      }
528020
function exposeGlobalTimers(config) {

    // Sets the global timeout value for all outgoing requests
    process.setOutgoingRequestsTimeout = function (val) {
        globalOutgoing = val;
    };

    // Sets the global timeout value for all incoming requests
    process.setIncomingRequestsTimeout = function (val) {
        globalIncoming = val;
    };

    // Sets the global timeout value for all incoming and outgoing requests
    process.setAllRequestsTimeout = function (val) {
        globalOutgoing = val;
        globalIncoming = val;
    };

    // set values from config
    config.global_timeout = parseInt(config.global_timeout, 10);
    if (config.global_timeout > 0) {
        process.setAllRequestsTimeout(config.global_timeout);
    }

    config.inc_req_timeout = parseInt(config.inc_req_timeout, 10);
    if (config.inc_req_timeout > 0) {
        process.setIncomingRequestsTimeout(config.inc_req_timeout);
    }

    config.out_req_timeout = parseInt(config.out_req_timeout, 10);
    if (config.out_req_timeout > 0) {
        process.setOutgoingRequestsTimeout(config.out_req_timeout);
    }

}
1059368
function timeout(opt) {

  var options = opt || Object.create(null);
  var my = {
    milliseconds: Number(options.milliseconds) || 5000,
    header: Boolean(options.header),
  };
  if (typeof options.callback == 'function') {
    my.callback = options.callback;
    my.data = options.data;
    return wrapper(my, true);
  }
  return wrapper(my, false);
}
356052
function cancel() {
    timeouts.forEach(function (timeout) {
      clearTimeout(timeout);
    });
    Object.keys(callbacks).forEach(function (key) {
      callbacks[key]('cancel');
      delete callbacks[key];
    });
    timeouts = [];
  }
172111
public void nodeTimeout(String nodeName) {
    if (nodeRestarter != null) {
      nodeRestarter.delete(nodeName);
    }
    Set<String> sessions = nodeManager.getNodeSessions(nodeName);
    Set<ClusterNode.GrantId> grantsToRevoke = nodeManager.deleteNode(nodeName);
    if (grantsToRevoke == null) {
      return;
    }
    handleRevokedGrants(nodeName, grantsToRevoke);
    handleDeadNode(nodeName, sessions);
    scheduler.notifyScheduler();
  }