util.js
function callbackified() {
    var args = [];
    for (var i = 0; i < arguments.length; i++) {
      args.push(arguments[i]);
    }

    var maybeCb = args.pop();
    if (typeof maybeCb !== 'function') {
      throw new TypeError('The last argument must be of type Function');
    }
    var self = this;
    var cb = function() {
      return maybeCb.apply(self, arguments);
    };
    // In true node style we process the callback on `nextTick` with all the
    // implications (stack, `uncaughtException`, `async_hooks`)
    original.apply(this, args)
      .then(function(ret) { process.nextTick(cb.bind(null, null, ret)) },
            function(rej) { process.nextTick(callbackifyOnRejected.bind(null, rej, cb)) });
  }
function callbackified() {
    var args = [];
    for (var i = 0; i < arguments.length; i++) {
      args.push(arguments[i]);
    }

    var maybeCb = args.pop();
    if (typeof maybeCb !== 'function') {
      throw new TypeError('The last argument must be of type Function');
    }
    var self = this;
    var cb = function() {
      return maybeCb.apply(self, arguments);
    };
    // In true node style we process the callback on `nextTick` with all the
    // implications (stack, `uncaughtException`, `async_hooks`)
    original.apply(this, args)
      .then(function(ret) { process.nextTick(cb.bind(null, null, ret)) },
            function(rej) { process.nextTick(callbackifyOnRejected.bind(null, rej, cb)) });
  }
function callbackified ( ) { var args = [ ] ; for ( var i = 0 ; i < arguments . length ; i ++ ) { args . push ( arguments [ i ] ) ; } var maybeCb = args . pop ( ) ; if ( typeof maybeCb !== 'function' ) { throw new TypeError ( 'The last argument must be of type Function' ) ; } var self = this ; var cb = function ( ) { return maybeCb . apply ( self , arguments ) ; } ; // In true node style we process the callback on `nextTick` with all the // implications (stack, `uncaughtException`, `async_hooks`) original . apply ( this , args ) . then ( function ( ret ) { process . nextTick ( cb . bind ( null , null , ret ) ) } , function ( rej ) { process . nextTick ( callbackifyOnRejected . bind ( null , rej , cb ) ) } ) ; }
We DO NOT return the promise as it gives the user a false sense that the promise is actually somehow related to the callback's execution and that the callback throwing will reject the promise.
We DO NOT return the promise as it gives the user a false sense that the promise is actually somehow related to the callback s execution and that the callback throwing will reject the promise .