Skip to content

codexar/npm-cb-promise

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cb-promise

Allow your methods be called by Callbacks or Promises (by Q).

Examples:

The use of this module is very simple and useful.

var cbPromise = require('cb-promise');

// Create your methods with a optional callback parameter
var getImportantData = function (cb) {
  var data = 'important data';
  return cbPromise(null, data, cb);
};

Yes, that's it. Now you can call your method using callback or promise

Using Callbacks:

getImportantData(function (err, data) {
  if (err) throw new Error(err);
  console.log(data);
});

Using Promises:

getImportantData().then(function (data) {
  console.log(data);
}, function (err) {
  throw new Error(err);
})

Handling Errors

There are no differences with the examples above.

var cbPromise = require('cb-promise');

// Create your methods with a optional callback parameter
var getImportantData = function (cb) {
  var error = 'error occurred';
  return cbPromise(error, null, cb);
};

About

Allow your methods be called by Callbacks or Promises.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published