# time-limit-promise

> Fulfill long runinng promises on timeout.

Latest version **1.0.4** (published 2018-06-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install time-limit-promise
pnpm add time-limit-promise
yarn add time-limit-promise
bun add time-limit-promise
```

## 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.0.4 |
| Published | 2018-06-21 |
| First published | 2015-12-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/time-limit-promise) |
| Module format | CommonJS |
| Node | >= 0.12 |
| Dependencies | 0 |
| Unpacked size | 4.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Ivan Nikulin |
| Maintainers | inikulin |
| Keywords | promise, timeout, time, timer, limit, resolve, reject |

## Links

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

## Alternatives

- [@js-joda/timezone](https://npm.io/package/@js-joda/timezone.md) — 383.4K weekly downloads
- [chartjs-adapter-moment](https://npm.io/package/chartjs-adapter-moment.md) — 210.8K weekly downloads
- [strftime](https://npm.io/package/strftime.md) — 171.2K weekly downloads
- [vue-flatpickr-component](https://npm.io/package/vue-flatpickr-component.md) — 115.8K weekly downloads
- [timepicker](https://npm.io/package/timepicker.md) — 51.0K weekly downloads

## Recent versions

- 1.0.4 (latest) — 2018-06-21
- 1.0.3 — 2018-05-23
- 1.0.2 — 2015-12-03
- 1.0.1 — 2015-12-03
- 1.0.0 — 2015-12-03

## README

# time-limit-promise
[![Build Status](https://api.travis-ci.org/inikulin/time-limit-promise.svg)](https://travis-ci.org/inikulin/time-limit-promise)

*Fulfill long runinng promises on timeout.*

Unlike other implementations on npm it has some nice extra features:
 - You can both reject and resolve promises on timeout
 - You can provide custom value with which promise will be rejected or resolved on timeout
 - Unrefs promise timer, so it will not block your app from exit.
 - Uses `Promise` implementation of the passed promise: no external implementation dependencies, no global `Promise` dependencies

## Install
```
npm install time-limit-promise
```

## Usage
```js
const timeLimit = require('time-limit-promise');
const fetch     = require('node-fetch');

var fetchPromise = fetch('https://github.com/inikulin');

timeLimit(fetchPromise, 50).then(res => {
    // If `fetchPromise` will be fulfilled within 50ms
    // time limited promise will be fullfilled as well.
    // Otherwise, it will be resolved with the `undefined` value.
});

timeLimit(fetchPromise, 50, { resolveWith: 'no content' }).then(res => {
    // Same as above, but on timeout it will
    // be resolved with the `no-content` value.
    console.log(res); // > no-content
});


timeLimit(fetchPromise, 50, { rejectWith: new Error('timeout') }).catch(err => {
    // Same as above, but on timeout it will
    // be rejected with the provided error.
    console.log(err.message); // > timeout
});

```

## Author
[Ivan Nikulin](https://github.com/inikulin) (ifaaan@gmail.com)

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