# @particle/await-on

> really simple error handling with await/async

Latest version **1.0.1** (published 2019-05-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install @particle/await-on
pnpm add @particle/await-on
yarn add @particle/await-on
bun add @particle/await-on
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2019-05-17 |
| First published | 2019-05-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=7.6 |
| Dependencies | 0 |
| Unpacked size | 3.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | Jason Yung |
| Maintainers | anatoly-particle, andrewparticle, busticated, cullenshane, debbie23, dmiddlecamp, elijthomas, idokleinman, jgoggins, jhagerman, jme783, mdma, monkbroc, mstan, particlebot, samt, sergeuz, suda, towynlin |
| Keywords | await, async, error, handler, handling, simple, try, catch, block, promise |

## Links

- npm: https://www.npmjs.com/package/@particle/await-on
- Repository: https://github.com/bitstrider/await-on
- Homepage: https://github.com/bitstrider/await-on#readme
- Issues: https://github.com/bitstrider/await-on/issues
- npm.io page: https://npm.io/package/@particle/await-on

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2019-05-17
- 1.0.0 — 2019-05-17

## README

# 😪 @particle/await-on
![npm](https://img.shields.io/npm/v/await-on.svg)
![node](https://img.shields.io/node/v/await-on.svg)
![npm](https://img.shields.io/npm/l/await-on.svg)
![npm](https://img.shields.io/npm/dt/await-on.svg)
![Travis](https://img.shields.io/travis/bitstrider/await-on.svg)
![Coveralls github](https://img.shields.io/coveralls/github/bitstrider/await-on.svg)

Really simple error handling with await/async

Forked from [`await-on`](https://github.com/json2d/await-on) by [Jason Yung](https://github.com/json2d), itself inspired by [`await-to-js`](https://github.com/scopsy/await-to-js) whose creator [Dima Grossman](http://blog.grossman.io/how-to-write-async-await-without-try-catch-blocks-in-javascript/) originally blogged about using destructuring array assignment

## Quick Usage
This package provides a helper for destructuring the results of a Promise:
```javascript
const on = require('@particle/await-on');

const fetchData = () => new Promise(/*...*/);

const [err, data] = await on(fetchData());
if(err) {
	res.send(err);
} else {
	res.send(data);
}
```

The goal is to avoid the built-in approach using the `try`/`catch` block pattern:

```javascript
try {
	const data = await fetchData();
	res.send(data);
} catch(err) {
	res.send(err);
}
```

## Type fuzziness
Non-promises will passthrough same as the behavior of the native `await`

```javascript
const [err, answer] = await on(42); //not a promise but ok no big deal
console.log(answer) //> 42
```

## License
MIT License. See [License](https://github.com/particle-iot/await-on/blob/master/LICENSE) in the repository.

---
_Source: https://npm.io/package/@particle/await-on · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
