https://github.com/kaufmanhenry/aplus-await
A simple way of handling async/await responses with array destructuring.
https://github.com/kaufmanhenry/aplus-await
async async-await destructuring javascript promise-wrapper promises
Last synced: 3 days ago
JSON representation
A simple way of handling async/await responses with array destructuring.
- Host: GitHub
- URL: https://github.com/kaufmanhenry/aplus-await
- Owner: kaufmanhenry
- License: mit
- Created: 2019-06-18T10:41:31.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T00:49:17.000Z (over 2 years ago)
- Last Synced: 2025-04-11T00:04:25.208Z (about 1 month ago)
- Topics: async, async-await, destructuring, javascript, promise-wrapper, promises
- Language: TypeScript
- Homepage:
- Size: 1.08 MB
- Stars: 5
- Watchers: 0
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# aplus-await [](https://travis-ci.org/hcjk/aplus-await)
A simple way of handling async/await responses with array destructuring. The original concept for this package was derived from [Promises/A+](https://promisesaplus.com).
## Install
```shell
$ yarn add aplus-await
```## Usage
```js
// 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:
```js
const [result] = await aplusAwait(promise);
```If you just want the error:
```js
const [,error] = await aplusAwait(promise);
```If you do not want to use array destructuring:
```js
const response = await aplusAwait(promise);
// response[0] = result
// response[1] = error
```## License
MIT © [Henry Kaufman](http://github.com/hcjk)