# promise-timeout

> Simple timeouts for promises

Latest version **1.3.0** (published 2018-02-18) · MIT license · 0 weekly downloads

## Install

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

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.0 |
| Published | 2018-02-18 |
| First published | 2015-11-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/promise-timeout) |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 60 |
| Author | David M. Lee, II |
| Maintainers | leedm777 |
| Keywords | promise, timeout |

## Links

- npm: https://www.npmjs.com/package/promise-timeout
- Repository: https://github.com/building5/promise-timeout
- Homepage: https://github.com/building5/promise-timeout#readme
- Issues: https://github.com/building5/promise-timeout/issues
- npm.io page: https://npm.io/package/promise-timeout

## 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

- 1.3.0 (latest) — 2018-02-18
- 1.2.0 — 2018-02-09
- 1.1.1 — 2017-03-21
- 1.1.0 — 2017-03-07
- 1.0.0 — 2015-11-18

## README

# promise-timeout

A super-simple way to put a timeout on promise resolution.

It assumes you already have either platform support for promises (Node 0.12 or
greater), or you have a polyfill (see [es6-promise][]).

## Installation

```bash
$ npm install promise-timeout
```

## Usage

### timeout(promise, timeoutMillis)

Rejects a promise with a `TimeoutError` if it does not settle within the
specified timeout. Parameters:

 * `promise: Promise` - Promise to monitor.
 * `timeoutMillis: number` - Number of milliseconds to wait on settling.

## TimeoutError

Exception indicating that the timeout expired.

## Examples

ES2015:

```javascript
import { timeout, TimeoutError } from 'promise-timeout';

let somePromise = goDoSomething();

timeout(somePromise, 1000)
  .then((thing) => console.log('I did a thing!'))
  .catch((err) => {
    if (err instanceof TimeoutError) {
      console.error('Timeout :-(');
    }
  });
```

ES5:

```javascript
'use strict';

var pt = require('promise-timeout');

var somePromise = goDoSomething();

pt.timeout(somePromise, 1000)
  .then(function (thing) {
    console.log('I did a thing!');
  }).catch(function (err) {
    if (err instanceof pt.TimeoutError) {
      console.error('Timeout :-(');
    }
  });
```

 [es6-promise]: https://www.npmjs.com/package/es6-promise

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