src/utils/co.js
function callbackify(func) {
  return function(...args) {
    if (args.length === 0
        || typeof args[args.length - 1] !== 'function') {
      throw new Error(`${func.name || 'Function'} requires a callback.`);
    }

    const callback = args.pop();

    func.call(this, ...args).then((value) => {
      setImmediate(() => callback(null, value));
    }, (err) => {
      setImmediate(() => callback(err));
    });
  };
}
function callbackify(func) {
  return function(...args) {
    if (args.length === 0
        || typeof args[args.length - 1] !== 'function') {
      throw new Error(`${func.name || 'Function'} requires a callback.`);
    }

    const callback = args.pop();

    func.call(this, ...args).then((value) => {
      setImmediate(() => callback(null, value));
    }, (err) => {
      setImmediate(() => callback(err));
    });
  };
}
function callbackify ( func ) { return function ( ... args ) { if ( args . length === 0 || typeof args [ args . length - 1 ] !== 'function' ) { throw new Error ( ` ${ func . name || 'Function' } ` ) ; } const callback = args . pop ( ) ; func . call ( this , ... args ) . then ( ( value ) => { setImmediate ( ( ) => callback ( null , value ) ) ; } , ( err ) => { setImmediate ( ( ) => callback ( err ) ) ; } ) ; } ; }
Wrap a promise-returning function
into a function that accepts a
node.js style callback.
@param {AsyncFunction} func
@returns {Function}
Wrap a promise - returning function into a function that accepts a node . js style callback .