# async_fn

> One-function library for calling asynchronous functions one by one in a queue

Latest version **1.0.0** (published 2024-10-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install async_fn
pnpm add async_fn
yarn add async_fn
bun add async_fn
```

## Health

**Score 45/100 (D)** — status: maintenance-mode.

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

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2024-10-11 |
| First published | 2016-02-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 17620 |
| Author | Sergey Shishkalov |
| Maintainers | s0ber, ertrzyiks |

## Links

- npm: https://www.npmjs.com/package/async_fn
- Repository: https://github.com/npm/npm
- Homepage: https://github.com/npm/npm#readme
- Issues: https://github.com/npm/npm/issues
- npm.io page: https://npm.io/package/async_fn

## Recent versions

- 1.0.0 (latest) — 2024-10-11
- 1.0.0-rc8 — 2024-10-11
- 1.0.0-rc7 — 2024-10-11
- 1.0.0-rc6 — 2024-09-19
- 1.0.0-rc5 — 2024-09-19
- 1.0.0-rc3 — 2024-09-18
- 1.0.0-rc2 — 2024-09-18
- 1.0.0-rc1 — 2024-09-18
- 1.0.0-rc — 2024-09-18
- 0.2.4 — 2018-08-17
- 0.2.3 — 2017-02-16
- 0.1.7 — 2017-01-12
- 0.2.2 — 2016-12-05
- 0.2.1 — 2016-11-23
- 0.2.0 — 2016-11-23
- … 1 more at https://npm.io/package/async_fn/versions

## README

AsyncFn
=====
[![Build Status](https://travis-ci.org/s0ber/async_fn.png?branch=master)](https://travis-ci.org/s0ber/async_fn)

## Description

This is one-method library, which main purpose is ability to run provided to this method asynchronous functions in a queue one by one.
Please notice, that all provided functions should return a promise and they should be asynchronous. Support for simple functions is not yet implemented, but planned.

### Example

Here's just a spec example.

```coffee
it 'calls callbacks in a queue one by one', (done) ->
  asyncFn1 = sinon.spy(=>
    dfd = new $.Deferred()
    setTimeout ->
      dfd.resolve()
    , 700
    dfd.promise()
  )

  asyncFn2 = sinon.spy(=>
    dfd = new $.Deferred()
    setTimeout ->
      dfd.resolve()
    , 300
    dfd.promise()
  )

  asyncFn3 = sinon.spy(=>
    dfd = new $.Deferred()
    setTimeout ->
      dfd.resolve()
    , 100
    dfd.promise()
  )

  AsyncFn.addToCallQueue asyncFn1
  AsyncFn.addToCallQueue asyncFn2
  AsyncFn.addToCallQueue asyncFn3

  expect(asyncFn2).to.be.not.called
  expect(asyncFn3).to.be.not.called

  setTimeout ->
    expect(asyncFn1).to.be.calledOnce
    expect(asyncFn2).to.be.calledOnce
    expect(asyncFn3).to.be.calledOnce
    expect(asyncFn1).to.be.calledBefore asyncFn2
    expect(asyncFn2).to.be.calledBefore asyncFn3
    done()
  , 1500
```

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