# callback-count

> Count your callbacks before continuing. A tiny control flow helper that supports dynamic counting.

Latest version **0.2.0** (published 2015-07-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install callback-count
pnpm add callback-count
yarn add callback-count
bun add callback-count
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2015-07-30 |
| First published | 2014-02-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Tejesh Mehta |
| Maintainers | tjmehta |
| Keywords | callback, count, callback, count, counter, control, flow, next, done, dynamic |

## Links

- npm: https://www.npmjs.com/package/callback-count
- Repository: https://github.com/tjmehta/callback-count
- Issues: https://github.com/tjmehta/callback-count/issues
- npm.io page: https://npm.io/package/callback-count

## Dependencies (1)

- [exists](https://npm.io/package/exists.md) ^1.0.0

## Recent versions

- 0.2.0 (latest) — 2015-07-30
- 0.1.0 — 2014-03-06
- 0.0.3 — 2014-02-25
- 0.0.2 — 2014-02-25
- 0.0.1 — 2014-02-25

## README

callback-count [![Build Status](https://travis-ci.org/tjmehta/callback-count.png)](https://travis-ci.org/tjmehta/callback-count)
==============

#### Count callbacks before continuing, tiny control flow helper, allows dynamic counting. 

### Flow control
```js
var callbackCount = require('callback-count');
var counter = callbackCount(done);

setTimeout(counter.inc().next, 100);
setTimeout(counter.inc().next, 100);

function done (err) {
  console.log('finished.');
}
```

### .inc() allows you to dynamically update the number of callbacks you are expecting.
```js
var callbackCount = require('callback-count');
var counter = callbackCount(done);

counter.inc().inc().inc();
counter.next().next().next();

function done (err) {
  console.log('finished.');
}
```

### The constructor can take an initial value for the count expected
```js
var callbackCount = require('callback-count');
var counter = callbackCount(3, done);

counter.next().next().next();

function done (err) {
  console.log('finished.');
}
```

### .next() decrements the count and callsback when the count has reached 0
```js
var counter = createCounter(3, done);

counter.next().next().next();

function done (err) {
  console.log(counter.count); // 0
  console.log('finished.');
}
```

### if .next() receives an error it will callback immediately
```js
var counter = createCounter(3, done);

counter.next(new Error('boom'));

function done (err) {
  console.log(err.message); // boom
}
```

### License: MIT

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