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): TimeoutCreates a timeout that will call the callback after the delay.
Type Parameters
TArgs extends any[]
Parameters
callback: Action<TArgs>The function to call.delay?: numberThe number of milliseconds to delay.immediate: boolean = trueWhether to call the callback immediately....args: TArgsThe 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 TimeoutProperties
| Name | Type | Description |
|---|---|---|
| isPending | boolean | readonly Whether the timeout is still pending. |
start method
ts
start(delay?: number, ...args: any[]): voidStart the timeout.
Parameters
delay?: numberThe number of milliseconds to delay....args: any[]The arguments to pass to the callback.
cancel method
ts
cancel(): voidCancel the timeout.
