promisify-func

Make function async (i.e. if function returns not Promise then it wraps it with Promise; if function throws error then wrap it with Promise.reject).


Keywords
promisify
License
MIT
Install
npm install promisify-func@0.0.4

Documentation

promisify-func

Make function async (i.e. if function returns not Promise then it wraps it with Promise; if function throws error then wrap it with Promise.reject).

Coverage Status Build Status

Example

const promisify = require('promisify-func');

const p = (url) => url;

promisify(p)(url).then(res => {
    //res == url
})

const t = () => {throw new Error()};

promisify(t)().catch(err => {
    //err == new Error()
})

//will do nothing for Promises
promisify(Promise.resolve("abc")).then(res => {
    //res == abc
})