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)

Creates a new Interval.

Parameters

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

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

Creates a new Interval.

Parameters

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

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

Creates a new Interval.

Parameters

  • callback: Action<TArgs> The function to be called when the interval elapses.
  • options?: number | IntervalOptions 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
delaynumberreadonly 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
delaynumberoptional Delay in milliseconds.
immediatebooleanoptional Whether to start the interval immediately.

MIT License, Made with ❤️