1.0.2 • Published 6 years ago

fn-callback-promisify v1.0.2

Weekly downloads
2
License
ISC
Repository
github
Last release
6 years ago

callback-promisify

npm install --save fn-callback-promisify

demo

USAGE

import { promisify } from 'fn-callback-promisify';
const fnObj = {
  print: (content, callback) => {
    callback(content === 'fail' ? 'new error' : null, content);
  }
}

// callback
fnObj.print("callback", () => {
  console.log('callback success');
});

// promisify
const promisifyFn = promisify(fnObj.print, fnObj);

promisifyFn('promise').then((content) => {
  return new Promise((resolve, reject) => {
    console.log('promise success');
    setTimeout(() => {
      resolve();
    }, 2000);
  });
}).then((content) => {
  console.log('promise success after 2s');
}).catch((err) => {
    //error
  console.log(err);
  throw new Error(err);
});
1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago