pinky-promises
v1.4.1
Published
Pinky Promises are the most lightweight alternatives to the modern web promises API, with support for all browsers and platforms and no dependencies.
Downloads
4
Maintainers
Readme
Pinky Promises are the most lightweight alternatives to the modern web promises API, with support for all browsers and platforms and no dependencies.
≪ Node package · Buy me a Coffee ≫
Made with ♥ by Jeffrey Lanters
Installation
Install using NPM for your JS or TS project.
$ npm install pinky-promises --save
JavaScript Usage
const { PinkyPromise } = require("pinky-promises");
import { PinkyPromise } from "pinky-promises";
getUser() {
return new PinkyPromise((resolve, reject) => {
// Do something ASYNC ...
resolve({ ... });
reject(error);
});
}
getUser()
.then(value => {})
.catch(reason => {})
.finally(_ => {});
Consuming
// Consume let's you cancel a unfulfilled promise.
const promise = getUser();
promise.consume();
Typings
Typings included!
const getUserData = (): PinkyPromise<IUserData> => {
// Use a generic to define the resolve type
return new PinkyPromise<IUserData>((resolve, reject) => {
// ...
});
};