src/index.js
function run() {
  const current = now();
  const queue = timeoutQueue.slice();
  let interval = INTERVAL_MAX;

  timeoutQueue.length = 0;

  // Reset
  if (runRafId > 0 || runTimeoutId > 0) {
    stop();
  }

  for (let i = queue.length - 1; i >= 0; i--) {
    const item = queue[i];

    if (!item.cancelled) {
      const duration = item.time - current;

      if (duration <= 0) {
        if (isDev) {
          debug('timeout triggered for "%s" at %s', item.id, new Date().toLocaleTimeString());
        }
        item.fn.apply(item.fn, item.args);
      } else {
        // Store smallest duration
        if (duration < interval) {
          interval = duration;
        }
        timeoutQueue.push(item);
      }
    }
  }

  // Loop
  if (timeoutQueue.length > 0) {
    // Use raf if requested interval is less than cutoff
    if (interval < INTERVAL_CUTOFF) {
      runRafId = raf(run);
    } else {
      runTimeoutId = setTimeout(run, interval);
    }
  }
}
function run() {
  const current = now();
  const queue = timeoutQueue.slice();
  let interval = INTERVAL_MAX;

  timeoutQueue.length = 0;

  // Reset
  if (runRafId > 0 || runTimeoutId > 0) {
    stop();
  }

  for (let i = queue.length - 1; i >= 0; i--) {
    const item = queue[i];

    if (!item.cancelled) {
      const duration = item.time - current;

      if (duration <= 0) {
        if (isDev) {
          debug('timeout triggered for "%s" at %s', item.id, new Date().toLocaleTimeString());
        }
        item.fn.apply(item.fn, item.args);
      } else {
        // Store smallest duration
        if (duration < interval) {
          interval = duration;
        }
        timeoutQueue.push(item);
      }
    }
  }

  // Loop
  if (timeoutQueue.length > 0) {
    // Use raf if requested interval is less than cutoff
    if (interval < INTERVAL_CUTOFF) {
      runRafId = raf(run);
    } else {
      runTimeoutId = setTimeout(run, interval);
    }
  }
}
function run ( ) { const current = now ( ) ; const queue = timeoutQueue . slice ( ) ; let interval = INTERVAL_MAX ; timeoutQueue . length = 0 ; // Reset if ( runRafId > 0 || runTimeoutId > 0 ) { stop ( ) ; } for ( let i = queue . length - 1 ; i >= 0 ; i -- ) { const item = queue [ i ] ; if ( ! item . cancelled ) { const duration = item . time - current ; if ( duration <= 0 ) { if ( isDev ) { debug ( 'timeout triggered for "%s" at %s' , item . id , new Date ( ) . toLocaleTimeString ( ) ) ; } item . fn . apply ( item . fn , item . args ) ; } else { // Store smallest duration if ( duration < interval ) { interval = duration ; } timeoutQueue . push ( item ) ; } } } // Loop if ( timeoutQueue . length > 0 ) { // Use raf if requested interval is less than cutoff if ( interval < INTERVAL_CUTOFF ) { runRafId = raf ( run ) ; } else { runTimeoutId = setTimeout ( run , interval ) ; } } }
Process outstanding queue items
Process outstanding queue items