callbackify.js 411 B

1234567891011121314151617
  1. var restArgs = require('./restArgs');
  2. exports = function(fn) {
  3. return restArgs(function(args) {
  4. var cb = args.pop();
  5. fn.apply(this, args).then(
  6. function(value) {
  7. cb(null, value);
  8. },
  9. function(err) {
  10. if (err === null) err = new Error();
  11. cb(err);
  12. }
  13. );
  14. });
  15. };
  16. module.exports = exports;