Huge News!Announcing our $40M Series B led by Abstract Ventures.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.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.6K
decreased by-21.4%
Maintainers
1
Weekly downloads
 
Created
Source

callback-count Build Status

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

Flow control

var counter = createCounter(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 counter = createCounter(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 counter = createCounter(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

FAQs

Package last updated on 06 Mar 2014

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc