Options
All
  • Public
  • Public/Protected
  • All
Menu

Class FixedRateTimer

Timer that is triggered in equal time intervals.

It has summetric cross-language implementation and is often used by Pip.Services toolkit to perform periodic processing and cleanup in microservices.

see

INotifiable

Example

class MyComponent {
    private timer: FixedRateTimer = new FixedRateTimer(() => { this.cleanup }, 60000);
    ...
    public open(correlationId: string, callback: (err: any) => void): void {
        ...
        timer.start();
        ...
    }

    public open(correlationId: string, callback: (err: any) => void): void {
        ...
        timer.stop();
        ...
    }

    private cleanup(): void {
        ...
    }
    ...
}

Hierarchy

  • FixedRateTimer

Implements

Index

Constructors

constructor

  • new FixedRateTimer(taskOrCallback?: any, interval?: number, delay?: number): FixedRateTimer
  • Creates new instance of the timer and sets its values.

    see

    setTask

    see

    setCallback

    see

    setInterval

    see

    setDelay

    Parameters

    • Default value taskOrCallback: any = null

      (optional) a Notifiable object or callback function to call when timer is triggered.

    • Default value interval: number = null

      (optional) an interval to trigger timer in milliseconds.

    • Default value delay: number = null

      (optional) a delay before the first triggering in milliseconds.

    Returns FixedRateTimer

Methods

close

  • close(correlationId: string, callback?: function): void
  • Closes the timer.

    This is required by [[ICloseable]] interface, but besides that it is identical to stop().

    see

    stop

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • Optional callback: function

      callback function that receives error or null no errors occured.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

getCallback

  • getCallback(): function
  • Gets the callback function that is called when this timer is triggered.

    Returns function

    the callback function or null if it is not set.

      • (): void
      • Returns void

getDelay

  • getDelay(): number
  • Gets initial delay before the timer is triggered for the first time.

    Returns number

    the delay in milliseconds.

getInterval

  • getInterval(): number
  • Gets periodic timer triggering interval.

    Returns number

    the interval in milliseconds

getTask

  • Gets the INotifiable object that receives notifications from this timer.

    Returns INotifiable

    the INotifiable object or null if it is not set.

isStarted

  • isStarted(): boolean
  • Checks if the timer is started.

    Returns boolean

    true if the timer is started and false if it is stopped.

setCallback

  • setCallback(value: function): void
  • Sets the callback function that is called when this timer is triggered.

    Parameters

    • value: function

      the callback function to be called.

        • (): void
        • Returns void

    Returns void

setDelay

  • setDelay(value: number): void
  • Sets initial delay before the timer is triggered for the first time.

    Parameters

    • value: number

      a delay in milliseconds.

    Returns void

setInterval

  • setInterval(value: number): void
  • Sets periodic timer triggering interval.

    Parameters

    • value: number

      an interval in milliseconds.

    Returns void

setTask

  • Sets a new INotifiable object to receive notifications from this timer.

    Parameters

    • value: INotifiable

      a INotifiable object to be triggered.

    Returns void

start

  • start(): void
  • Starts the timer.

    Initially the timer is triggered after delay. After that it is triggered after interval until it is stopped.

    see

    stop

    Returns void

stop

  • stop(): void
  • Stops the timer.

    see

    start

    Returns void

Generated using TypeDoc