# promx

> a natural/modern/safer way to handle promise in async/await

Latest version **2.0.2** (published 2019-02-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install promx
pnpm add promx
yarn add promx
bun add promx
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2019-02-21 |
| First published | 2018-04-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | mouafa |
| Maintainers | mouafa |
| Keywords | promise, async, await, error, handling |

## Links

- npm: https://www.npmjs.com/package/promx
- Repository: https://github.com/mouafa/promx
- Homepage: https://github.com/mouafa/promx#readme
- Issues: https://github.com/mouafa/promx/issues
- npm.io page: https://npm.io/package/promx

## Alternatives

- [promise-throttle](https://npm.io/package/promise-throttle.md) — 44.2K weekly downloads
- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads

## Recent versions

- 2.0.2 (latest) — 2019-02-21
- 2.0.0-beta.4 (beta) — 2019-02-15
- 0.2.0-alpha.c3998fac (canary) — 2018-04-20
- 2.0.1 — 2019-02-21
- 2.0.0 — 2019-02-21
- 2.0.0-beta.3 — 2019-02-15
- 2.0.0-beta.2 — 2019-02-14
- 2.0.0-beta.1 — 2019-02-14
- 2.0.0-beta.0 — 2019-02-14
- 1.0.1 — 2018-05-04
- 1.0.0 — 2018-04-20
- 0.1.6 — 2018-04-20
- 0.1.5 — 2018-04-20
- 0.1.4 — 2018-04-20
- 0.1.3 — 2018-04-20
- … 3 more at https://npm.io/package/promx/versions

## README

<p align="center"><img width="auto" src="https://raw.githubusercontent.com/mouafa/promx/master/assets/cover.png"></p>

<p align="center"> A natural/modern/safer way to handle promise in async/await </p>

[![npm version](https://badge.fury.io/js/promx.svg)](https://badge.fury.io/js/promx)
[![codecov](https://codecov.io/gh/mouafa/promx/branch/master/graph/badge.svg)](https://codecov.io/gh/mouafa/promx)
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
[![Build Status](https://api.travis-ci.org/mouafa/promx.svg?branch=master)](https://travis-ci.org/mouafa/promx#)

## Installation

```console
$ yarn add promx
```

If you prefer using npm:

```console
$ npm i -S promx
```

## Usage

promx will allow you to write code like this:

```js
import promx from 'promx'

async function main() {
  const [err, res] = await promx(fetch('http://example.com/movies.json'))
  if (err) console.warn('failed to load data')
  else console.log({ res })
}

main()
```

Instead of this:

```js
async function main() {
  try {
    await fetch('http://example.com/movies.json')
  } catch (err) {
    console.warn('failed to load data')
    return
  }
  console.log({ res })
}

main()
```

---

timeout the promise if it took longer then 1 second:

```js
import promx from 'promx'

async function main() {
  const [err, res] = await promx(fetch('http://example.com/movies.json'), { timeout: 1000 })
  if (err) console.warn('failed to load data')
  else console.log({ res })
}

main()
```

## API

promx(promise, [options])

#### promise

Type: `Promise`

Receives a promise that will eventually resolve or reject

#### options

Type: `Object`

##### options.timeout

Type: `Number`

timeout duration in ms before resolving with timout error

## License

MIT © mouafa

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