my-deferred
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

My-Deferred

A tiny library to help with promises you can check and resolve from outside

Installation

Just add the npm package to your project with

npm install -S my-deferred

Usage

This is how you create a deferred and resolve it later.

const def = new Deferred<string>();
// def.val will now return null;

def.promise.then((val) => {
  console.log(`Promise has been resolved with ${val}!`)
})

console.log(def.isPending())
// prints true

console.log(def.isResolved())
// prints false

def.resolve("Hello World");
// will now output "Promise has been resolved with Hello World!"

you can also reject the deferred using

const def = new Deferred<string>();

def.promise
  .then(() => console.log("won't happen"))
  .catch(err => console.log(err))

def.reject({
  message: "something has gone wrong!"
});
// Will now print out "somehting has gone wrong!"

/my-deferred/

    Package Sidebar

    Install

    npm i my-deferred

    Weekly Downloads

    3,154

    Version

    1.2.0

    License

    MIT

    Unpacked Size

    11.7 kB

    Total Files

    17

    Last publish

    Collaborators

    • relief.melone