Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

kaufmanhenry/aplus-await

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aplus-await travis-badge

A simple way of handling async/await responses with array destructuring. The original concept for this package was derived from Promises/A+.

Install

$ yarn add aplus-await

Usage

// Instead of writing
let result;
try {
  result = await promise();
} catch (error) {
  throw new Error(error);
}
console.log(result);

// You can write
const [result, error] = await aplusAwait(promise);
if (error) throw new Error(error);
console.log(result);

API

When you wrap a promise with aplusAwait, you are guaranteed to be returned two arguments in the form of an array. The first element is the response of the promise and the second element is any error that occurred while executing the promise.

If you do not care about the error:

const [result] = await aplusAwait(promise);

If you just want the error:

const [,error] = await aplusAwait(promise);

If you do not want to use array destructuring:

const response = await aplusAwait(promise);
// response[0] = result
// response[1] = error

License

MIT © Henry Kaufman

About

A simple way of handling async/await responses with array destructuring.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.