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
Name | Type | Description |
---|---|---|
isActive | boolean | get Whether the interval is currently active. |
delay | number | undefined | get 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
Name | Type | Description |
---|---|---|
delay | number | readonly optional Delay in milliseconds. |
isActive | boolean | readonly 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
Name | Type | Description |
---|---|---|
delay | number | optional Delay in milliseconds. |
immediate | boolean | optional Whether to start the interval immediately. |