🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

callback-count

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

callback-count

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

0.2.0
latest
Source
npm
Version published
Maintainers
1
Created
Source

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

Keywords

callback

FAQs

Package last updated on 30 Jul 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts