promisify-optional-callback

1.0.1 • Public • Published

Promisify

Promisify converts a function that takes a callback into a function that takes a callback or returns a promise.

Installation

npm install promisify-optional-callback

Usage

const promisify = require('promisify-optional-callback');
 
function example(callback) {
    console.log('Hello world');
 
    callback();
}
 
const examplePromise = promisify(example);
 
examplePromise(function (error) {
    console.log('Inside a callback');
});
 
// OR
 
examplePromise()
.then(function () {
    console.log('Inside a promise');
})
.catch(function (error) {
    console.log('Experienced an error');
});
 

If callback is called with a non-null object as its first argument, that is handled as an error and the promise will reject.

Readme

Keywords

none

Package Sidebar

Install

npm i promisify-optional-callback

Weekly Downloads

5

Version

1.0.1

License

MIT

Last publish

Collaborators

  • eric.dahlseng