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

    Function scheduleTimeout

    Creates and starts a timer which executes a function or specified piece of code once the timer expires, this is simular to using setTimeout but provides a return object for cancelling and restarting (refresh) the timer.

    The timer may be cancelled (cleared) by calling the cancel() function on the returned ITimerHandler, or you can "reschedule" and/or "restart" the timer by calling the refresh() function on the returned ITimerHandler instance

    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 the timeout.

    let timeoutCalled = false;
    let theTimeout = scheduleTimeout(() => {
    // This callback will be called after 100ms as this uses setTimeout()
    timeoutCalled = true;
    }, 100);

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

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

    // You can also "restart" the timer, whether it has previously triggered not not via the `refresh()`
    theTimeout.refresh();
    • Creates and starts a timer which executes a function or specified piece of code once the timer expires, this is simular to using setTimeout but provides a return object for cancelling and restarting (refresh) the timer.

      The timer may be cancelled (cleared) by calling the cancel() function on the returned ITimerHandler, or you can "reschedule" and/or "restart" the timer by calling the refresh() function on the returned ITimerHandler instance

      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 the timeout.

      0.4.4

      let timeoutCalled = false;
      let theTimeout = scheduleTimeout(() => {
      // This callback will be called after 100ms as this uses setTimeout()
      timeoutCalled = true;
      }, 100);

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

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

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