Time to resolve promise in miliseconds
Value to resolve promise with
Key to cancel the timeout if needed
Will be throwed in cancelling promise when the timer has already finished or cancelled
Will be throwed in cancelling promise when the timer has not found via identifier
The default timeout cancelling rejection error Will be throwed when the timer has cancelled
Usage via promise instance:
import { timeout } from "@thalesrc/js-utils/promise";
const timeout = timeout(1000);
timeout
.then(() => console.log("this won't be logged"))
.catch(() => console.log("this will be logged, because timer has been cancelled"));
timeout.cancel(timeout);
Usage via key
import { timeout } from "@thalesrc/js-utils/promise";
const key = Symbol();
timeout(1000, null, key)
.then(() => console.log("this won't be logged"))
.catch(() => console.log("this will be logged, because timer has been cancelled"));
timeout.cancel(key);
Static usage example:
import "@thalesrc/js-utils/promise/static/timeout";
const timeout = Promise.timeout(1000);
timeout
.then(() => console.log("this won't be logged"))
.catch(() => console.log("this will be logged, because timer has been cancelled"));
Promise.timeout.cancel(timeout);
The identifier of the promise to cancel
The error which will be throwed by the cancelled promise
A promise which resolves if cancelling process is successfull, rejects otherwise
Generated using TypeDoc
timeout