Search…
Promise Helpers
Various helpers related to promise specific functionality.
Source code is hosted on GitHub
yarn
npm
yarn add @corets/promise-helpers
npm install --save @corets/promise-helpers

createTimeout()

A promisified version of the setTimeout function:
import { createTimeout } from "@corets/promise-helpers"
await createTimeout(2000)

createPromise()

Create a promise that you can pass around without specifying the resolve function upfront:
import { createPromise } from "@corets/promise-helpers"
const runWhenResolved = async (promise: Promise<any>) => {
try {
const result = await promise
console.log("promise resolved with:", result)
} catch (err) {
console.error("an error was thrown from promise:", err)
}
}
const promise = createPromise()
// pass promise to another function
runWhenResolved(promise)
promise.resolve("some data")
// or
promise.reject("reason...")
Copy link
On this page
createTimeout()
createPromise()