The delay duration in milliseconds
Optional
value: TOptional value to resolve the promise with
A promise that resolves after the specified delay with the provided value
import { delay } from '@consumidor-positivo/ts-utils';
// Basic usage - wait for 1 second
await delay(1000);
console.log('This logs after 1 second');
// Chain with other async operations
async function fetchWithDelay() {
await delay(500); // wait 500ms before fetching
return fetch('https://api.example.com/data');
}
// Use with a value to pass through the promise chain
const result = await delay(1000, 'resolved value');
console.log(result); // 'resolved value' after 1 second
Creates a promise that resolves after the specified duration.
This utility function is useful for introducing delays in async operations, implementing timeouts, or controlling the flow of asynchronous code.