• Pauses execution for a specified number of milliseconds.

    Example


    import { delay, sleep } from "@mrspartak/promises"
    import { parsePage } from "./parser"

    for (let i = 0; i < 10; i++) {
    // Parse the page and wait for 1 second before parsing the next page
    const pageData = await parsePage(i)
    await delay(1000)
    }

    // You can also use alias sleep instead of delay
    await sleep(1000)

    Parameters

    • ms: number

      The number of milliseconds to delay execution.

    Returns Promise<void>

    A promise that resolves after the specified delay.

    Throws

    Thrown if the input is not a number or if the number is negative.