delayed
delayed<
T>(ms:number,result:T):Promise<T>
Defined in: extras/delay.ts:32
Returns a promise that resolves with the given result after a delay.
Use cases:
- Simulating asynchronous operations in tests
- Creating time-based effects in applications
- Returning a value after a delay without blocking the main thread
Type Parameters
Section titled “Type Parameters”| Type Parameter | Description |
|---|---|
T | The type of the result |
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
ms | number | Milliseconds to delay |
result | T | Value to resolve after the delay |
Returns
Section titled “Returns”Promise<T>
Promise that resolves with the result after the delay
Example
Section titled “Example”await delayed(1000, 'done'); // Resolves with 'done' after 1 second