Skip to content

Interval

Repeatedly calls a function or executes a code snippet, with a time delay between each call, with controls to pause & resume the interval.

Interval class

ts
class Interval<TArgs extends any[] = []> implements IInterval

Represents a repeated calls of a function with a time delay between each call.

Type Parameters

  • TArgs extends any[] = [] Type of arguments to pass to the callback function.

Constructors

ts
constructor(callback: Action, delay?: number | undefined)

Creates a new Interval.

Parameters

  • callback: Action The function to be called when the interval elapses.
  • delay?: number | undefined The delay between each call in milliseconds.

ts
constructor(callback: Action, options?: IntervalOptions | undefined)

Creates a new Interval.

Parameters

  • callback: Action The function to be called when the interval elapses.
  • options?: IntervalOptions | undefined The options for the interval.

ts
constructor(callback: Action<TArgs>, options?: number | IntervalOptions | undefined, ...args: TArgs)

Creates a new Interval.

Parameters

  • callback: Action<TArgs> The function to be called when the interval elapses.
  • options?: number | IntervalOptions | undefined The options for the interval.
  • ...args: TArgs Arguments to pass to the callback function.

Properties

NameTypeDescription
isActivebooleanget Whether the interval is currently active.
delaynumber | undefinedget Delay in milliseconds.

pause method

ts
pause(): void

Pauses the interval.

resume method

ts
resume(): void

Resumes the interval.

IInterval interface

ts
interface IInterval

Interface that represent a repeated calls of a function.

Properties

NameTypeDescription
delaynumber | undefinedreadonly optional Delay in milliseconds.
isActivebooleanreadonly Whether the interval is currently active.

pause method

ts
pause(): void

Pauses the interval.

resume method

ts
resume(): void

Resumes the interval.

IntervalOptions interface

ts
interface IntervalOptions

Options for the Interval class.

Properties

NameTypeDescription
delaynumber | undefinedoptional Delay in milliseconds.
immediateboolean | undefinedoptional Whether to start the interval immediately.

MIT License, Made with ❤️