• Creates a promise that resolves after a specified delay.

    Parameters

    • ms: number

      The delay in milliseconds.

    Returns Promise<void>

    A promise that resolves after the specified delay.

    Example

    // Basic usage
    await sleep(1000); // Pauses execution for 1 second

    Example

    // Using in an async function
    async function example() {
    console.log('Start');
    await sleep(2000);
    console.log('2 seconds later');
    }

    Example

    // Using with .then()
    sleep(3000).then(() => console.log('3 seconds have passed'));