lib/hypertimer.js
function _schedule() {
    // do not _schedule when there are timeouts in progress
    // this can be the case with async timeouts in non-paced mode.
    // _schedule will be executed again when all async timeouts are finished.
    if (!paced && Object.keys(current).length > 0) {
      return;
    }

    var next = timeouts[0];

    // cancel timer when running
    if (timeoutId) {
      clearTimeout(timeoutId);
      timeoutId = null;
    }

    if (running && next) {
      // schedule next timeout
      var time = next.time;
      var delay = time - timer.now();
      var realDelay = paced ? delay / rate : 0;

      function onTimeout() {
        // when running in non-paced mode, update the hyperTime to
        // adjust the time of the current event
        if (!paced) {
          hyperTime = (time > hyperTime && isFinite(time)) ? time : hyperTime;
        }

        // grab all expired timeouts from the queue
        var expired = _getExpiredTimeouts(time);
        // note: expired.length can never be zero (on every change of the queue, we reschedule)

        // execute all expired timeouts
        if (paced) {
          // in paced mode, we fire all timeouts in parallel,
          // and don't await their completion (they can do async operations)
          expired.forEach(function (timeout) {
            _execTimeout(timeout);
          });

          // schedule the next round
          _schedule();
        }
        else {
          // in non-paced mode, we execute all expired timeouts serially,
          // and wait for their completion in order to guarantee deterministic
          // order of execution
          function next() {
            var timeout = expired.shift();
            if (timeout) {
              _execTimeout(timeout, next);
            }
            else {
              // schedule the next round
              _schedule();
            }
          }
          next();
        }
      }

      timeoutId = setTimeout(onTimeout, Math.round(realDelay));
      // Note: Math.round(realDelay) is to defeat a bug in node.js v0.10.30,
      //       see https://github.com/joyent/node/issues/8065
    }
  }
function _schedule() {
    // do not _schedule when there are timeouts in progress
    // this can be the case with async timeouts in non-paced mode.
    // _schedule will be executed again when all async timeouts are finished.
    if (!paced && Object.keys(current).length > 0) {
      return;
    }

    var next = timeouts[0];

    // cancel timer when running
    if (timeoutId) {
      clearTimeout(timeoutId);
      timeoutId = null;
    }

    if (running && next) {
      // schedule next timeout
      var time = next.time;
      var delay = time - timer.now();
      var realDelay = paced ? delay / rate : 0;

      function onTimeout() {
        // when running in non-paced mode, update the hyperTime to
        // adjust the time of the current event
        if (!paced) {
          hyperTime = (time > hyperTime && isFinite(time)) ? time : hyperTime;
        }

        // grab all expired timeouts from the queue
        var expired = _getExpiredTimeouts(time);
        // note: expired.length can never be zero (on every change of the queue, we reschedule)

        // execute all expired timeouts
        if (paced) {
          // in paced mode, we fire all timeouts in parallel,
          // and don't await their completion (they can do async operations)
          expired.forEach(function (timeout) {
            _execTimeout(timeout);
          });

          // schedule the next round
          _schedule();
        }
        else {
          // in non-paced mode, we execute all expired timeouts serially,
          // and wait for their completion in order to guarantee deterministic
          // order of execution
          function next() {
            var timeout = expired.shift();
            if (timeout) {
              _execTimeout(timeout, next);
            }
            else {
              // schedule the next round
              _schedule();
            }
          }
          next();
        }
      }

      timeoutId = setTimeout(onTimeout, Math.round(realDelay));
      // Note: Math.round(realDelay) is to defeat a bug in node.js v0.10.30,
      //       see https://github.com/joyent/node/issues/8065
    }
  }
function _schedule ( ) { // do not _schedule when there are timeouts in progress // this can be the case with async timeouts in non-paced mode. // _schedule will be executed again when all async timeouts are finished. if ( ! paced && Object . keys ( current ) . length > 0 ) { return ; } var next = timeouts [ 0 ] ; // cancel timer when running if ( timeoutId ) { clearTimeout ( timeoutId ) ; timeoutId = null ; } if ( running && next ) { // schedule next timeout var time = next . time ; var delay = time - timer . now ( ) ; var realDelay = paced ? delay / rate : 0 ; function onTimeout ( ) { // when running in non-paced mode, update the hyperTime to // adjust the time of the current event if ( ! paced ) { hyperTime = ( time > hyperTime && isFinite ( time ) ) ? time : hyperTime ; } // grab all expired timeouts from the queue var expired = _getExpiredTimeouts ( time ) ; // note: expired.length can never be zero (on every change of the queue, we reschedule) // execute all expired timeouts if ( paced ) { // in paced mode, we fire all timeouts in parallel, // and don't await their completion (they can do async operations) expired . forEach ( function ( timeout ) { _execTimeout ( timeout ) ; } ) ; // schedule the next round _schedule ( ) ; } else { // in non-paced mode, we execute all expired timeouts serially, // and wait for their completion in order to guarantee deterministic // order of execution function next ( ) { var timeout = expired . shift ( ) ; if ( timeout ) { _execTimeout ( timeout , next ) ; } else { // schedule the next round _schedule ( ) ; } } next ( ) ; } } timeoutId = setTimeout ( onTimeout , Math . round ( realDelay ) ) ; // Note: Math.round(realDelay) is to defeat a bug in node.js v0.10.30, //       see https://github.com/joyent/node/issues/8065 } }
Reschedule all queued timeouts
@private
Reschedule all queued timeouts