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
}
export function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
Creates a promise that resolves after the specified delay. Useful for adding delays in async operations or rate limiting.