await-call

0.0.0 • Public • Published

await-call await-call

Async await wrapper for easy error handling without try-catch

Installation

$ npm install await-call

Example

const call = require('await-call');
 
const findUserById = async id => {
  if(Math.random() > .5)
    throw Error('BOOM!');
  return { name: 'lsong' };
};
 
const cb = err => {
  console.error('Oh! No..', err);
};
 
(async () => {
    
  const [ err, user ] = await call(findUserById(1));
  if(err) return cb('user not found');
  console.log(`hello ${user.name}`);
 
})();

Contributing

  • Fork this Repo first
  • Clone your Repo
  • Install dependencies by $ npm install
  • Checkout a feature branch
  • Feel free to add your features
  • Make sure your features are fully tested
  • Publish your local branch, Open a pull request
  • Enjoy hacking <3

MIT

This work is licensed under the MIT license.


Package Sidebar

Install

npm i await-call

Weekly Downloads

0

Version

0.0.0

License

MIT

Unpacked Size

3.12 kB

Total Files

5

Last publish

Collaborators

  • song940