# method-timeout-rejection

> Promisify a method and reject it if it takes more than a set duration

Latest version **1.0.0** (published 2017-05-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install method-timeout-rejection
pnpm add method-timeout-rejection
yarn add method-timeout-rejection
bun add method-timeout-rejection
```

## 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.0 |
| Published | 2017-05-16 |
| First published | 2017-05-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | mathieutamer |
| Keywords | promise, timeout, callback, lambda |

## Links

- npm: https://www.npmjs.com/package/method-timeout-rejection
- Repository: https://git@github.com/Precogs-com/method-timeout-rejection
- Homepage: https://github.com/Precogs-com/method-timeout-rejection#readme
- Issues: https://github.com/Precogs-com/method-timeout-rejection/issues
- npm.io page: https://npm.io/package/method-timeout-rejection

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

- 1.0.0 (latest) — 2017-05-16

## README

# method timeout rejection

> Reject method (encapsulate in a promise) if it takes more than a set duration

### Usage

Constructor defines a timeout in milliseconds.
```javascript
const MethodTimeoutRejection = require('method-timeout-rejection');

const methodTimeout = new MethodTimeoutRejection(1000);
```

Method `timeoutRejection` wraps a callback in a promise and define a timeout in milliseconds.
If the callback return something in that time then it acts in the exact same way as
the original callback, otherwise it's rejected with a specific `MethodTimeOutError` error.

```javascript
methodTimeout.timeoutRejection((callback) => {
  setTimeout(() => {
    callback(null, 'hello');
  }, 2000);
})
.catch((err) => {
  assert(err instanceof MethodTimeoutRejection.MethodTimeOutError);
});
```

Method `hasExpired` just returns true if inside the timeoutRejection method, the global callback has timeout.

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