cpsenize

2.0.0 • Public • Published

cpsenize

Wraps synchronous functions with a cps (callback passing style) function

 
var cpsenize = require('cpsenize');
 
function add(a, b){
    return a + b;
}
 
var cpsAdd = cpsenize(add);
 
cpsAdd(5, 6, function(error, result){
    console.log(result); // 11
});
 
 

Additionally can also return errors if the function throws

 
var cpsenize = require('cpsenize');
 
function add(a, b){
    throw new Error('BANG!!!');
}
 
var cpsAdd = cpsenize(add, true);
 
cpsAdd(5, 6, function(error, result){
    console.log(error); // BANG!!!
});
 
 

Package Sidebar

Install

npm i cpsenize

Weekly Downloads

2,929

Version

2.0.0

License

MIT

Last publish

Collaborators

  • mauricebutler