super-promise

1.0.2 • Public • Published

SuperPromise

A promise that you can rely on!

This is basically just a promise with support for callbacks in case you want to maintain legacy support but also allow for more advanced features like await in async functions.

Depends on bluebird.

Usage:

new SuperPromise((resolve,reject)=>{}, callback)

If callback is not undefined, it will be called and the promise will not be resolved. If callback is undefined, it will not be called and the promise will be resolved.

Example usage:

function makeRequest(url, cb) {
    return new SuperPromise((resolve, reject)=>{
        request(url, (err, res, body)=>{
            if(err){
                reject(err);
            }
            else if(res.statusCode != 200){
                reject(res.statusCode);
            }
            else{
                resolve(body);
            }
        })
    }, cb);
}

Calling this method with the parameters [cat.com, null] will cause it to be resolved as a promise. Calling this method with the parameters with the parameters [cat.com, (err, res)=>{ }] will cause the callback to be called and the promise unresolved.

Though some may find it stupid, I find this decently useful. I prefer not having to refactor 30ish files across a variety of projects just so that a personal project can support async.

Readme

Keywords

none

Package Sidebar

Install

npm i super-promise

Weekly Downloads

3

Version

1.0.2

License

ISC

Last publish

Collaborators

  • arcticzeroo