async-wrapus
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

async-wrapus

Wrapper for async functions without pain. No try catches anymore.

NPM JavaScript Style Guide Badges Badges Badges Badges Badges Badges

Description

Wrapper returns array of Error object and Result. In case function throws no exception it will return [null, resultObject]. In case function throws with exception it will return [Error, null].

Install

npm install --save async-wrapus
yarn add  async-wrapus

Usage

import asyncWrap from 'async-wrapus';

const asyncRequest = async () => {
  // Can throw exception!
  return await someApiRequest();
};

const someMethod = async () => {
  /**
   * err: null | Error
   * result: Result of asyncRequest | null
   */
  const [err, result] = await asyncWrap(asyncRequest());

  if (err) {
    // do something with exception
  }

  if (result) {
    // do something with result
  }
};

Package Sidebar

Install

npm i async-wrapus

Weekly Downloads

7

Version

1.0.4

License

MIT

Unpacked Size

78.2 kB

Total Files

15

Last publish

Collaborators

  • kolengri