timeout
Set a time limit for the execution of a specific block of code.
timeout function
ts
function timeout<TArgs extends any[]>(callback: Action<TArgs>, delay?: number, immediate: boolean = true, ...args: TArgs): Timeout
Creates a timeout that will call the callback after the delay.
Type Parameters
TArgs extends any[]
Parameters
callback: Action<TArgs>
The function to call.delay?: number
The number of milliseconds to delay.immediate: boolean = true
Whether to call the callback immediately....args: TArgs
The arguments to pass to the callback.
Return Timeout
An object with a start method to start the timeout, a cancel method to cancel the timeout, and an isPending property to check if the timeout is still pending.
Timeout interface
ts
interface Timeout
Properties
Name | Type | Description |
---|---|---|
isPending | boolean | readonly Whether the timeout is still pending. |
start method
ts
start(delay?: number, ...args: any[]): void
Start the timeout.
Parameters
delay?: number
The number of milliseconds to delay....args: any[]
The arguments to pass to the callback.
cancel method
ts
cancel(): void
Cancel the timeout.