• A simple utility returning a promise that is resolved after the specified time. Optionally you can also provide a value to return.

    Type Parameters

    • T = undefined

    Parameters

    • Optional delay: number

      How long for the promise to resolve. If not provided defaults to 0 so execution is delayed to next tick (like with setTimeout(..., 0))

    • Optional value: T

      Optional value to resolve the promise with. If not given undefined is used.

    Returns Promise<T>

    A promise.

    Example

    Using only the first argument.

    async function mockLoadPerson1(): Promise<Person> {
    await delay(100); // We simulate an async response
    return {
    name: "John",
    surname: "Doe",
    email: "jdoe@mailinator.com",
    username: "john"
    };
    }

    Using both the first arguments.

    async function mockLoadPerson2(): Promise<Person> {
    return delay(100, {
    name: "John",
    surname: "Doe",
    email: "jdoe@mailinator.com",
    username: "john"
    });
    }

Generated using TypeDoc