/controllable-promise

Control when a JavaScript promise resolves or rejects.

Primary LanguageTypeScriptMIT LicenseMIT

codecov

Controllable Promise

Control when a JavaScript promise resolves or rejects.

Getting started

npm i controllable-promise

Create the promise and manually invoke the resolve function:

import ControllablePromise from 'controllable-promise';

const setupPromise = new ControllablePromise()

setupPromise.then(() => {
    executeSomeAfterSetupLogic();
})

callSomeSetupLogic();

setupPromise.resolve();

Or use the promise as you would normally:

import ControllablePromise from 'controllable-promise';

const setupPromise = new ControllablePromise(resolve => {
    callSomeSetupLogic();

    // Below is optional, you can still manually invoke the `resolve`
    // later using `setupPromise.resolve()`
    resolve();
})

await setupPromise;

executeSomeAfterSetupLogic();