# exclusive-promise

> Use this when you have a function that returns a promise and you want that promise to be canceled if the function is called again.

Latest version **1.0.1** (published 2017-02-09) · CC0-1.0 license · 0 weekly downloads

## Install

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

## 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.1 |
| Published | 2017-02-09 |
| First published | 2016-10-02 |
| Weekly downloads | 0 |
| License | CC0-1.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Johnny Hauser |
| Maintainers | m59 |
| Keywords | cancel, promise, only, one, exclusive, wrap, previous, call |

## Links

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

## Dependencies (1)

- [bluebird](https://npm.io/package/bluebird.md) ^3.4.6

## 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.1 (latest) — 2017-02-09
- 1.0.0 — 2016-10-02

## README

# exclusive-promise

Use this when you have a function that returns a promise and you want that promise to be canceled if the function is called again.

*\* Native promises don't support cancellation, so you must use bluebird `Promise`*

## install

```sh
npm install exclusive-promise bluebird
```

## example

```js
const Promise = require('bluebird')
const exclusivePromise = require('exclusive-promise')

const fn = () => {
  return new Promise((resolve, reject) => {

  }).then(() => {
    // in this example, "a" will be canceled and will not reach this point
    // "b" will reach this point
  })
}
const exclusiveFn = exclusivePromise(fn)
const a = exclusiveFn() // promise chain "a" begins
const b = exclusiveFn() // promise chain "a" is canceled, "b" begins
```

## API

### exclusivePromise(fn)

- `fn: function` a function that creates and returns a promise
- **returns**: `function` a function that calls `fn` after canceling the promise from the previous call. Arguments are passed through to `fn`.

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