Neanderthal Pudding Mix
Publish your own packages to the world's most popular software ecosystem with npm Pro.Get started »

callback-promise-union

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

Keywords

none

Install

npm i callback-promise-union

DownloadsWeekly Downloads

6

Version

1.0.1

License

MIT

Unpacked Size

3.69 kB

Total Files

5

Last publish

Collaborators

  • avatar