callback-count
Count your callbacks before continuing. A tiny control flow helper that supports dynamic counting.
Last updated 11 years ago by tjmehta .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install callback-count 
SYNC missed versions from official npm registry.

callback-count Build Status

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

Flow control

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.

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

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

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

var counter = createCounter(3, done);

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

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

License: MIT

Current Tags

  • 0.2.0                                ...           latest (11 years ago)

5 Versions

  • 0.2.0                                ...           11 years ago
  • 0.1.0                                ...           12 years ago
  • 0.0.3                                ...           12 years ago
  • 0.0.2                                ...           12 years ago
  • 0.0.1                                ...           12 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 0
Dependencies (1)
Dev Dependencies (2)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |