# @gradientedge/single-promise

> Ensures that only a single promise/request is made while waiting for the original request to complete

Latest version **1.0.2** (published 2023-02-07) · ISC license · 0 weekly downloads

## Install

```sh
npm install @gradientedge/single-promise
pnpm add @gradientedge/single-promise
yarn add @gradientedge/single-promise
bun add @gradientedge/single-promise
```

## Health

**Score 35/100 (D)** — status: abandoned.

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

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2023-02-07 |
| First published | 2022-07-08 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Jimmy Thomson |
| Maintainers | gradient_edge, spocked, hemalshah, jameswiltshire, jimmythomson |

## Links

- npm: https://www.npmjs.com/package/@gradientedge/single-promise
- Repository: https://github.com/gradientedge/common-utils
- Homepage: https://github.com/gradientedge/common-utils#readme
- Issues: https://github.com/gradientedge/common-utils/issues
- npm.io page: https://npm.io/package/@gradientedge/single-promise

## Recent versions

- 1.0.2 (latest) — 2023-02-07
- 1.0.1 — 2022-08-22
- 1.0.0 — 2022-07-08

## README

# `@gradientedge/single-promise`

Given a function (that returns a promise) and a key, this function ensures that the function is not 
called multiple times, but instead allows multiple calls to it to all wait on the same promise.

Minimal example:
```typescript
import { singlePromise } from '@gradientedge/single-promise'

const grant = await singlePromise('accessToken', () => {
  return client.post('https://some-auth-endpoint')
})
```

In the example above, it's the anonymous function that only gets called once while there may have been
multiple calls to the actual `singlePromise` function. The `accessToken` string is the key that the
`singlePromise` function uses internally to check for an existing promise.

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