@js-bits/xpromise
TypeScript icon, indicating that this package has built-in type declarations

1.0.15 • Public • Published

Extendable Promise

Allows extension of JavaScript's standard, built-in Promise class and decouples an asynchronous operation that ties an outcome to a promise from the constructor.

Installation

Install with npm:

npm install @js-bits/xpromise

Install with yarn:

yarn add @js-bits/xpromise

Import where you need it:

import ExtendablePromise from '@js-bits/xpromise';

or require for CommonJS:

const ExtendablePromise = require('@js-bits/xpromise');

How to use

class MyPromise extends ExtendablePromise {
  // do whatever you need
}

const myPromise = new MyPromise((resolve, reject) => {
  console.log('executed', resolve, reject);
});
console.log(myPromise instanceof Promise); // true
myPromise.execute(); // 'executed' [Function (anonymous)] [Function (anonymous)]
myPromise.then(result => {
  console.log(result); // 123
});
myPromise.resolve(123);

Notes

Package Sidebar

Install

npm i @js-bits/xpromise

Weekly Downloads

1

Version

1.0.15

License

ISC

Unpacked Size

28.7 kB

Total Files

16

Last publish

Collaborators

  • apolo-gh