@paradoxu/promiser
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

Promiser

Make your promises prettier with this simple wrapper, that can help you write promises without using a callback!

Usage

function foo() {
    const promiser = new Promiser();

    setTimeout(() => {
        let lucky = Math.random();

        if (lucky > 0.8)
            promiser.resolve("Oh yes! You're very lucky!");
        else
            promiser.reject("I suggest you to try again :( ... next year");
    }, 1500);

    return promiser.promise;
}

You can also check if a Promiser instance has already been solved by calling promiser.isSolved getter which will return true if promiser has been solved and false if not.

A single instance of Promiser can be used only once, so once you have solved your promise, that instance can't be reused for resolving/rejecting any other value!

Dependencies (0)

    Dev Dependencies (2)

    Package Sidebar

    Install

    npm i @paradoxu/promiser

    Weekly Downloads

    0

    Version

    0.0.1

    License

    ISC

    Unpacked Size

    11.9 kB

    Total Files

    7

    Last publish

    Collaborators

    • paradoxu