Get unlimited public & private packages + package-based permissions with npm Pro.Get started »

This package has been deprecated

Author message:

this package has been deprecated

@h-reser/deferred

1.1.0 • Public • Published

@h-reser/deferred

Build Status npm version dependencies Status devDependencies Status

A lightweight deferred implementation with Typescript support, inspired by jQuery and based on Javascript's Promise.

Installation

npm i @h-reser/deferred

Usage

import Deferred from "@h-reser/deferred";

// Create deferred object
const d = new Deferred();

// Implement logic
function playLottery() {
  setTimeout(() => {
    const random = Math.floor(Math.random() * Math.floor(2));
    if (random === 1)
      d.resolve("You have won!");
    else d.reject("You have lost...");
  }, 500);
};

// Handle Defered fulfillments and rejections
d
  .then((res) => {
    console.log(res + " :)");
  })
  .catch((e) => {
    console.error(e + " :(");
  })
  .finally(() => {
    console.log("Thanks for playing!");
  });

// Execute logic
playLottery();

When to use

Can be used in any environment which supports ES6's promises

Install

npm i @h-reser/deferred

DownloadsWeekly Downloads

0

Version

1.1.0

License

MIT

Unpacked Size

9.85 kB

Total Files

12

Last publish

Collaborators

  • avatar