🚀 Big News:Socket Has Acquired Secure Annex.Learn More →
Socket
Book a DemoSign in
Socket

manual-promise

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

manual-promise

A drop in replacement for JS `Promise` that exposes the `resolve` and `reject` function to scopes that have access to the promise instance; Plain JS promise can only be resolved or rejected from inside the function passed to the constructor of that promis

latest
Source
npmnpm
Version
2.0.2
Version published
Weekly downloads
27
80%
Maintainers
1
Weekly downloads
 
Created
Source

manual-promise

A drop in replacement for JS Promise that exposes the resolve and reject function to scopes that have access to the promise instance; Plain JS promise can only be resolved or rejected from inside the function passed to the constructor of that promise, ManualPromise allows the promise to be resolved or rejected from outside itself.

Installation

yarn add manual-promise

npn install manual-promise

How

Extends Promise so

new ManualPromise() instanceof Promise === true

Other solutions on the internet use a proxy or wrapper class for promise so they do not function as a drop in replacement.

Use


import { ManualPromise } from "manual-promise";

const prom = new ManualPromise();

prom.resolve(2);

// actions can still be run inside the promise
const prom2 = new ManualPromise((resolve, reject) => {
	// ... code
});

The class also exists on window, so the import is optional. Add to your global.d.ts file if using typescript and do not wish to import.

View the test file for examples.

Keywords

promise

FAQs

Package last updated on 18 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts