@nevware21/ts-utils
    Preparing search index...

    Function scheduleInterval

    Repeatedly calls a function or executes a code snippet, with a fixed time delay between each call.

    0.4.4

    The function to be executed after the timer expires.

    The time, in milliseconds that the timer should wait before the specified function or code is executed. If this parameter is omitted, a value of 0 is used, meaning execute "immediately", or more accurately, the next event cycle.

    Additional arguments which are passed through to the function specified by callback.

    A ITimerHandler instance which can be used to cancel or refresh the interval.

    let intervalCalled = 0;
    let theIntervalTimer = scheduleInvertal(() => {
    // This callback will be called every 100ms as this uses setInterval()
    intervalCalled++;
    }, 100);

    // Instead of calling clearInterval() with the returned value from setInterval() the returned
    // handler instance can be used instead to cancel the timer
    theIntervalTimer.cancel();
    theIntervalTimer.enabled; // false

    // You can start the timer via enabled
    theIntervalTimer.enabled = true;

    // Or you can also "restart" the timer, whether it has previously triggered not not via the `refresh()`
    theIntervalTimer.refresh();
    • Repeatedly calls a function or executes a code snippet, with a fixed time delay between each call.

      Type Parameters

      • A extends any[]

      Parameters

      • callback: (...args: A) => void

        The function to be executed after the timer expires.

      • timeout: number

        The time, in milliseconds that the timer should wait before the specified function or code is executed. If this parameter is omitted, a value of 0 is used, meaning execute "immediately", or more accurately, the next event cycle.

      • ...args: A

        Additional arguments which are passed through to the function specified by callback.

      Returns ITimerHandler

      A ITimerHandler instance which can be used to cancel or refresh the interval.

      0.4.4

      let intervalCalled = 0;
      let theIntervalTimer = scheduleInvertal(() => {
      // This callback will be called every 100ms as this uses setInterval()
      intervalCalled++;
      }, 100);

      // Instead of calling clearInterval() with the returned value from setInterval() the returned
      // handler instance can be used instead to cancel the timer
      theIntervalTimer.cancel();
      theIntervalTimer.enabled; // false

      // You can start the timer via enabled
      theIntervalTimer.enabled = true;

      // Or you can also "restart" the timer, whether it has previously triggered not not via the `refresh()`
      theIntervalTimer.refresh();