kutlugsahin / callback2promise

convert node style callbacks to promise

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

callback2promise

Converts functions with node style callbacks to promise (es6)

installation

npm install callback2promise --save

usage

var c2p = require('callback2promise');

// ordinary function with any number of parameters and a callback at the end
var nodeStyleFunc = function(param1, param2, callback){
  setTimeout(
    function(){ 
      callback(null, 'done') 
    }, 200);
}

// convert the function to a promise
var promise = c2p(nodeStyleFunc)(param1, param2);

promise
  .then(result => console.log(result))
  .catch(err => console.log(err));

About

convert node style callbacks to promise

License:MIT License


Languages

Language:JavaScript 100.0%