Creates a promise that resolves after the specified delay. Useful for adding delays in async operations or rate limiting.
The number of milliseconds to sleep
A promise that resolves after the specified delay
async function example() { console.log("Start"); await sleep(1000); // Waits 1 second console.log("End"); // Prints after delay}// For rate limiting:for (const item of items) { await processItem(item); await sleep(100); // Wait 100ms between items} Copy
async function example() { console.log("Start"); await sleep(1000); // Waits 1 second console.log("End"); // Prints after delay}// For rate limiting:for (const item of items) { await processItem(item); await sleep(100); // Wait 100ms between items}
Creates a promise that resolves after the specified delay. Useful for adding delays in async operations or rate limiting.