# @zcong/singleflight

> singleflight for js

Latest version **0.3.1** (published 2022-06-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install @zcong/singleflight
pnpm add @zcong/singleflight
yarn add @zcong/singleflight
bun add @zcong/singleflight
```

## Health

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

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

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.1 |
| Published | 2022-06-26 |
| First published | 2019-07-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | zcong1993 |
| Maintainers | zcong |

## Links

- npm: https://www.npmjs.com/package/@zcong/singleflight
- Repository: https://github.com/zcong1993/singleflight
- Issues: https://github.com/zcong1993/singleflight/issues
- npm.io page: https://npm.io/package/@zcong/singleflight

## Recent versions

- 0.3.1 (latest) — 2022-06-26
- 0.3.1-beta.0 (beta) — 2022-06-26
- 0.3.0 — 2021-07-31
- 0.2.0 — 2021-04-30
- 0.1.3 — 2020-03-11
- 0.1.2 — 2019-08-08
- 0.1.1 — 2019-07-23
- 0.1.0 — 2019-07-02

## README

# singleflight

[![NPM version](https://img.shields.io/npm/v/@zcong/singleflight.svg?style=flat)](https://npmjs.com/package/@zcong/singleflight) [![NPM downloads](https://img.shields.io/npm/dm/@zcong/singleflight.svg?style=flat)](https://npmjs.com/package/@zcong/singleflight) [![JS Test](https://github.com/zcong1993/singleflight/actions/workflows/js-test.yml/badge.svg)](https://github.com/zcong1993/singleflight/actions/workflows/js-test.yml) [![codecov](https://codecov.io/gh/zcong1993/singleflight/branch/master/graph/badge.svg)](https://codecov.io/gh/zcong1993/singleflight)

> singleflight for js

## Install

```sh
$ yarn add @zcong/singleflight
# or npm
$ npm i @zcong/singleflight --save
```

## Example

```ts
import { Singleflight } from '../src'

const sf = new Singleflight()

const delay = (n: number) => new Promise((resolve) => setTimeout(resolve, n))

const fn = async () => {
  console.log('fn called')
  await delay(1000)
  return 'fn result'
}

const errFn = async () => {
  console.log('err fn called')
  await delay(2000)
  throw new Error('panic')
}

Array(10)
  .fill(null)
  .forEach(() => {
    sf.do('test', fn).then(console.log).catch(console.log)

    sf.do('test-err', errFn)
      .then(console.log)
      .catch((err) => console.log(`err: ${err.message}`))
  })
```

## License

MIT &copy; zcong1993

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