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 IIntervalRepresents 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: ActionThe function to be called when the interval elapses.delay?: number | undefinedThe delay between each call in milliseconds.
ts
constructor(callback: Action, options?: IntervalOptions | undefined)Creates a new Interval.
Parameters
callback: ActionThe function to be called when the interval elapses.options?: IntervalOptions | undefinedThe 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 | undefinedThe options for the interval....args: TArgsArguments 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(): voidPauses the interval.
resume method
ts
resume(): voidResumes the interval.
IInterval interface
ts
interface IIntervalInterface that represent a repeated calls of a function.
Properties
| Name | Type | Description |
|---|---|---|
| delay | number | undefined | readonly optional Delay in milliseconds. |
| isActive | boolean | readonly Whether the interval is currently active. |
pause method
ts
pause(): voidPauses the interval.
resume method
ts
resume(): voidResumes the interval.
IntervalOptions interface
ts
interface IntervalOptionsOptions for the Interval class.
Properties
| Name | Type | Description |
|---|---|---|
| delay | number | undefined | optional Delay in milliseconds. |
| immediate | boolean | undefined | optional Whether to start the interval immediately. |
