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

    Interface ITimerHandler

    A Timer handler which is returned from scheduleTimeout which contains functions to cancel or restart (refresh) the timeout function.

    0.4.4

    interface ITimerHandler {
        cancel(): void;
        enabled: boolean;
        hasRef(): boolean;
        ref(): this;
        refresh(): ITimerHandler;
        unref(): this;
    }
    Index

    Properties

    Methods

    Properties

    enabled: boolean

    Gets or Sets a flag indicating if the underlying timer is currently enabled and running. Setting the enabled flag to the same as it's current value has no effect, setting to true when already true will not refresh() the timer. And setting to false will cancel() the timer.

    0.8.1

    let theTimer = createTimeout(...);

    // Check if enabled
    theTimer.enabled; // false

    // Start the timer
    theTimer.enabled = true; // Same as calling refresh()
    theTimer.enabled; //true

    // Has no effect as it's already running
    theTimer.enabled = true;

    // Will refresh / restart the time
    theTimer.refresh()

    let theTimer = scheduleTimeout(...);

    // Check if enabled
    theTimer.enabled; // true

    Methods

    • Cancels a timeout that was previously scheduled, after calling this function any previously scheduled timer will not execute.

      Returns void

      let theTimer = scheduleTimeout(...);
      theTimer.cancel();
    • If true, any running referenced ITimerHandler instance will keep the Node.js event loop active.

      Returns boolean

      0.7.0

      let theTimer = createTimeout(...);

      // Unreference the timer so that the runtime (Node) may terminate if nothing else is running.
      theTimer.unref();
      let hasRef = theTimer.hasRef(); // false

      theTimer.ref();
      hasRef = theTimer.hasRef(); // true
    • When called, requests that the event loop not exit so long when the ITimerHandler is active. Calling timer.ref() multiple times will have no effect. By default, all ITimerHandler objects will create "ref'ed" instances, making it normally unnecessary to call timer.ref() unless timer.unref() had been called previously.

      Returns this

      the ITimerHandler instance

      0.7.0

      let theTimer = createTimeout(...);

      // Make sure the timer is referenced (the default) so that the runtime (Node) does not terminate
      // if there is a waiting referenced timer.
      theTimer.ref();
    • Reschedules the timer to call its callback at the previously specified duration adjusted to the current time. This is useful for refreshing a timer without allocating a new JavaScript object.

      Using this on a timer that has already called its callback will reactivate the timer. Calling on a timer that has not yet executed will just reschedule the current timer.

      Returns ITimerHandler

      let theTimer = scheduleTimeout(...);
      // The timer will be restarted (if already executed) or rescheduled (if it has not yet executed)
      theTimer.refresh();
    • When called, the any active ITimerHandler instance will not require the event loop to remain active (Node.js). If there is no other activity keeping the event loop running, the process may exit before the ITimerHandler instance callback is invoked. Calling timer.unref() multiple times will have no effect.

      Returns this

      the ITimerHandler instance

      0.7.0

      let theTimer = createTimeout(...);

      // Unreference the timer so that the runtime (Node) may terminate if nothing else is running.
      theTimer.unref();