# awesome-only-resolves-last-promise

> Wraps an async function and ensure only last call will actually resolve/reject

Latest version **1.0.3** (published 2019-02-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install awesome-only-resolves-last-promise
pnpm add awesome-only-resolves-last-promise
yarn add awesome-only-resolves-last-promise
bun add awesome-only-resolves-last-promise
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2019-02-26 |
| First published | 2019-02-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=8 |
| Dependencies | 1 |
| Unpacked size | 7.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 29 |
| Author | slorber |
| Maintainers | slorber |

## Links

- npm: https://www.npmjs.com/package/awesome-only-resolves-last-promise
- Repository: https://github.com/slorber/awesome-only-resolves-last-promise
- npm.io page: https://npm.io/package/awesome-only-resolves-last-promise

## Dependencies (1)

- [awesome-imperative-promise](https://npm.io/package/awesome-imperative-promise.md) ^1.0.1

## Recent versions

- 1.0.3 (latest) — 2019-02-26
- 1.0.2 — 2019-02-22
- 1.0.1 — 2019-02-22
- 1.0.0 — 2019-02-21

## README

# awesome-only-resolves-last-promise

[![NPM](https://img.shields.io/npm/dm/awesome-only-resolves-last-promise.svg)](https://www.npmjs.com/package/awesome-only-resolves-last-promise)
[![Build Status](https://travis-ci.com/slorber/awesome-only-resolves-last-promise.svg?branch=master)](https://travis-ci.com/slorber/awesome-only-resolves-last-promise)

## Install

```bash
npm install --save awesome-only-resolves-last-promise
// or
yarn add awesome-only-resolves-last-promise
```

## Features

- Wraps an existing async function
- When calling the wrapped function multiple times consecutively, only the last returned promise will resolve and formerly returned promises will be cancelled (they won't resolve nor reject)

## Usage

```typescript jsx
import { onlyResolvesLast } from 'awesome-only-resolves-last-promise';

const asyncFunction = async (arg: number, arg2: string) => {
  await delay(100);
  return `val ${arg} ${arg2}`;
};

const wrappedAsyncFunction = onlyResolvesLast(asyncFunction);

const promise1 = wrappedAsyncFunction(1, '1');
const promise2 = wrappedAsyncFunction(2, '2');
const promise3 = wrappedAsyncFunction(3, '3');

// promise1 and promise2 will never resolve/reject
// promise3 will resolve in 100ms
```

Useful as an implementation detail of [awesome-debounce-promise](https://github.com/slorber/awesome-debounce-promise).

## License

MIT © [slorber](https://github.com/slorber)

# Hire a freelance expert

Looking for a React/ReactNative freelance expert with more than 5 years production experience?
Contact me from my [website](https://sebastienlorber.com/) or with [Twitter](https://twitter.com/sebastienlorber).

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