callback-promise-union
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Callback Promise

Promise with callback

Installation

npm i -S callback-promise-union
yarn add callback-promise-union

Example

const {CallbackPromise} = require('../');

function asyncCallbackFunc(error, result, cb) {
  const cp = new CallbackPromise(cb);
  cp.callback(error, result);
  return cp.promise;
}

function asyncFunc(error, result, cb) {
  const cp = new CallbackPromise(cb);
  if (error) {
    cp.reject(error);
  } else {
    cp.resolve(result);
  }
  return cp.promise;
}

function callbackFunc(error, result, cb) {
  cb(error, result);
}

function callbackAsyncFunc(error, result) {
  const cp = new CallbackPromise();
  callbackFunc(error, result, cp.delegate);
  return cp.promise;
}

(async () => {
  await asyncCallbackFunc('error', 'result');
  await asyncFunc('error', 'result');
  await callbackAsyncFunc('error', 'result');
})();

Author

License

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i callback-promise-union

      Weekly Downloads

      0

      Version

      1.0.1

      License

      MIT

      Unpacked Size

      3.69 kB

      Total Files

      5

      Last publish

      Collaborators

      • lnsoo