# promise-over

> A promise extension for over duration, timeout, and expiration.

Latest version **0.1.10** (published 2018-09-06) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install promise-over
pnpm add promise-over
yarn add promise-over
bun add promise-over
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.1.10 |
| Published | 2018-09-06 |
| First published | 2018-08-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 387.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | ViPro |
| Maintainers | vdustr |
| Keywords | promise, over, timeout, expire, async, await |

## Links

- npm: https://www.npmjs.com/package/promise-over
- Repository: git@github.com:VdustR/promise-over
- Homepage: https://github.com/VdustR/promise-over
- Issues: https://github.com/VdustR/promise-over/issues
- npm.io page: https://npm.io/package/promise-over

## Alternatives

- [@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
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 0.1.10 (latest) — 2018-09-06
- 0.1.9 — 2018-08-11
- 0.1.8 — 2018-08-09
- 0.1.7 — 2018-08-08
- 0.1.6 — 2018-08-08
- 0.1.5 — 2018-08-08
- 0.1.4 — 2018-08-08
- 0.1.3 — 2018-08-08
- 0.1.2 — 2018-08-08
- 0.1.1 — 2018-08-08
- 0.1.0 — 2018-08-08

## README

# promise-over

[![NPM](https://nodei.co/npm/promise-over.png)](https://nodei.co/npm/promise-over/)

A promise extension for over duration, timeout, and expiration.

## Install

```bash
npm i promise-over
# or using yarn
yarn add promise-over
```

CDN:

```html
<script src="https://unpkg.com/promise-over/dist/promiseOver.umd.min.js"></script>
```

Notice that `promise-finally` [polyfill](https://github.com/tc39/proposal-promise-finally/blob/master/polyfill.js) is required if you want to support browsers not supporting `promise-finally`.

## Usage

### Essential

```javascript
// es5
var promiseOver = require('promise-over')
// es6+
import promiseOver from 'promise-over'
// tree shaking(babel is required)
import promiseOver from 'promise-over/src/promise-over'
import expire from 'promise-over/src/expire'
import over from 'promise-over/src/over'
import timeoutExpire from 'promise-over/src/timeout-expire'
import timeout from 'promise-over/src/timeout'

promiseOver.over(asyncMethod, 5000).then(() => {
  // this will be called after over 5 seconds
})

promiseOver.timeout(asyncMethod, () => {
  // This would be called if `asyncMethod` was not resolved(or rejected) yet in 5 seconds
}, 5000)

promiseOver.expire(asyncMethod, 5000, new Error('Expired!!!'))
// An error with message `Expired!!!` would be thrown if `asyncMethod` was not resolved(or rejected) yet in 5 seconds
```

### Advanced

```javascript
// promiseOver = over + timeout + expire
promiseOver(asyncMethod, overDelay, [timeoutFunction, timeoutDelay], [expireDelay[, thrownOnExpired]])

promiseOver(getPeople(), 1000)
// the same as promiseOver.over(getPeople(), 1000)

promiseOver(getPeople(), 1000, () => showWaitingMessage(), 1000, 5000)

// timeoutExpire = timeout + expire
promiseOver.timeoutExpire(asyncMethod, timeoutFunction, timeoutDelay, [expireDelay[, thrownOnExpired])

promiseOver.timeoutExpire(getPeople(), () => showWaitingMessage(), 1000)
// the same as promiseOver.timeout(getPeople(), () => showWaitingMessage(), 1000)

// example:
promiseOver.timeoutExpire(getPeople(), () => showWaitingMessage(), 1000, 5000)
  .catch(err => {
    if (promiseOver.isExpireError(err)) {
      showExpiredMessage()
    }
  )

// with async / await
try {
  await promiseOver(getPeople(), () => showWaitingMessage(), 1000, 5000)
} catch(err) {
  if (promiseOver.isExpireError(err)) {
    showExpiredMessage()
  }
}
```

## Demo

Check timeline [here](https://vdustr.github.io/promise-over).

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