JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3181
  • Score
    100M100P100Q119612F
  • License MIT

Package Exports

  • my-deferred
  • my-deferred/dist/index.js
  • my-deferred/dist/src
  • my-deferred/dist/src/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (my-deferred) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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!"