Promise Helpers

Various helpers related to promise specific functionality.

Source code is hosted on GitHub

yarn add @corets/promise-helpers


A promisified version of the setTimeout function:

import { createTimeout } from "@corets/promise-helpers"

await createTimeout(2000)


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

promise.resolve("some data")
// or

Last updated