Optional
delay: numberHow 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: TOptional value to resolve the promise with. If not given undefined
is used.
A promise.
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
A simple utility returning a promise that is resolved after the specified time. Optionally you can also provide a value to return.