Skip to content

🍭 Make async requests sweet again! Wrapper for async functions without pain. No try catches anymore.

License

Notifications You must be signed in to change notification settings

kolengri/async-wrapus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
  }
};

About

🍭 Make async requests sweet again! Wrapper for async functions without pain. No try catches anymore.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published