1.0.13 • Published 8 years ago

promisecb v1.0.13

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

promisecb Build Status

Make callback function return as Promise

Install

$ npm install --save promisecb

Usage

promisecb(fn, args)

import promisecb from 'promisecb';

const setTimeoutPromise = promisecb(setTimeout, 5000);
setTimeoutPromise
  .then(() => {
    console.log('5 seconds');
  });

With this

import promisecb from 'promisecb';

const queryPromise = promisecb(database.query.bind(database), 'something');
queryPromise
  .then((result) => {
    console.log(result);
  }).catch((error) => {
    console.error(error);
  });

With async/await (ES2017)

import promisecb from 'promisecb';

const asyncFunc = async () => {
  try {
    const result = await promisecb(database.query.bind(database), 'something');
    console.log(result);
  } catch (error) {
    console.error(error);
  }
}

License

MIT © MichaelQQ

1.0.13

8 years ago

1.0.12

8 years ago

1.0.11

8 years ago

1.0.8

8 years ago

1.0.0

8 years ago