Timeout.set()method
Cancel any existing timeout and set a new one.
set(callback: Callback | undefined = this._callback, ms: number = this._ms): void
new Timeout(callback: Callback | undefined = undefined, ms = 0)
| Param | Type | |
|---|---|---|
callback | Callback | The default callback to run when a timeout fires (used by set() when no callback is passed). Defaults to undefined |
ms | unknown | The default delay for any created timeouts (in ms). Defaults to 0 |
| Return | |
|---|---|
Timeout | Stateful wrapper around setTimeout() that manages a single pending timeout at a time. |
| Property | Type | |
|---|---|---|
.exists | boolean | Whether a timeout is currently pending. required readonly |
Stateful wrapper around setTimeout() that manages a single pending timeout at a time.
setTimeout().const timeout = new Timeout(() => console.log("fired"), 1000);
timeout.set(); // Fires the callback after 1000ms.
timeout.clear(); // Cancels it before it fires.Cancel any existing timeout and set a new one.
set(callback: Callback | undefined = this._callback, ms: number = this._ms): void
Cancel any existing timeout.
clear(): void