lib/hypertimer.js
function _execTimeout(timeout, callback) {
    // store the timeout in the queue with timeouts in progress
    // it can be cleared when a clearTimeout is executed inside the callback
    current[timeout.id] = timeout;

    function finish() {
      // in case of an interval we have to reschedule on next cycle
      // interval must not be cleared while executing the callback
      if (timeout.type === TYPE.INTERVAL && current[timeout.id]) {
        timeout.occurrence++;
        timeout.time = timeout.firstTime + timeout.occurrence * timeout.interval;
        _queueTimeout(timeout);
        //console.log('queue timeout', timer.getTime().toISOString(), new Date(timeout.time).toISOString(), timeout.occurrence) // TODO: cleanup
      }

      // remove the timeout from the queue with timeouts in progress
      delete current[timeout.id];

      callback && callback();
    }

    // execute the callback
    try {
      if (timeout.callback.length == 0) {
        // synchronous timeout,  like `timer.setTimeout(function () {...}, delay)`
        timeout.callback();
        finish();
      } else {
        // asynchronous timeout, like `timer.setTimeout(function (done) {...; done(); }, delay)`
        timeout.callback(finish);
      }
    } catch (err) {
      // emit or log the error
      if (hasListeners(timer, 'error')) {
        timer.emit('error', err);
      }
      else {
        console.log('Error', err);
      }

      finish();
    }
  }
function _execTimeout(timeout, callback) {
    // store the timeout in the queue with timeouts in progress
    // it can be cleared when a clearTimeout is executed inside the callback
    current[timeout.id] = timeout;

    function finish() {
      // in case of an interval we have to reschedule on next cycle
      // interval must not be cleared while executing the callback
      if (timeout.type === TYPE.INTERVAL && current[timeout.id]) {
        timeout.occurrence++;
        timeout.time = timeout.firstTime + timeout.occurrence * timeout.interval;
        _queueTimeout(timeout);
        //console.log('queue timeout', timer.getTime().toISOString(), new Date(timeout.time).toISOString(), timeout.occurrence) // TODO: cleanup
      }

      // remove the timeout from the queue with timeouts in progress
      delete current[timeout.id];

      callback && callback();
    }

    // execute the callback
    try {
      if (timeout.callback.length == 0) {
        // synchronous timeout,  like `timer.setTimeout(function () {...}, delay)`
        timeout.callback();
        finish();
      } else {
        // asynchronous timeout, like `timer.setTimeout(function (done) {...; done(); }, delay)`
        timeout.callback(finish);
      }
    } catch (err) {
      // emit or log the error
      if (hasListeners(timer, 'error')) {
        timer.emit('error', err);
      }
      else {
        console.log('Error', err);
      }

      finish();
    }
  }
function _execTimeout ( timeout , callback ) { // store the timeout in the queue with timeouts in progress // it can be cleared when a clearTimeout is executed inside the callback current [ timeout . id ] = timeout ; function finish ( ) { // in case of an interval we have to reschedule on next cycle // interval must not be cleared while executing the callback if ( timeout . type === TYPE . INTERVAL && current [ timeout . id ] ) { timeout . occurrence ++ ; timeout . time = timeout . firstTime + timeout . occurrence * timeout . interval ; _queueTimeout ( timeout ) ; //console.log('queue timeout', timer.getTime().toISOString(), new Date(timeout.time).toISOString(), timeout.occurrence) // TODO: cleanup } // remove the timeout from the queue with timeouts in progress delete current [ timeout . id ] ; callback && callback ( ) ; } // execute the callback try { if ( timeout . callback . length == 0 ) { // synchronous timeout,  like `timer.setTimeout(function () {...}, delay)` timeout . callback ( ) ; finish ( ) ; } else { // asynchronous timeout, like `timer.setTimeout(function (done) {...; done(); }, delay)` timeout . callback ( finish ) ; } } catch ( err ) { // emit or log the error if ( hasListeners ( timer , 'error' ) ) { timer . emit ( 'error' , err ) ; } else { console . log ( 'Error' , err ) ; } finish ( ) ; } }
Execute a timeout
@param {{id: number, type: number, time: number, callback: function}} timeout
@param {function} [callback]
The callback is executed when the timeout's callback is
finished. Called without parameters
@private
Execute a timeout