callback-count
Advanced tools
Comparing version 0.0.3 to 0.1.0
@@ -20,3 +20,3 @@ var noop = function () {}; | ||
if (this.err) { | ||
return; // already errored | ||
return this; // already errored | ||
} | ||
@@ -28,3 +28,3 @@ else if (err) { | ||
else { | ||
this.count--; | ||
if (this.count > 0) this.count--; | ||
results = Array.prototype.slice.call(arguments, 1); | ||
@@ -31,0 +31,0 @@ this.results.push(results); |
{ | ||
"name": "callback-count", | ||
"version": "0.0.3", | ||
"version": "0.1.0", | ||
"description": "Count your callbacks before continuing. A tiny control flow helper that supports dynamic counting.", | ||
@@ -30,3 +30,7 @@ "main": "index.js", | ||
}, | ||
"homepage": "https://github.com/tjmehta/callback-count" | ||
"homepage": "https://github.com/tjmehta/callback-count", | ||
"devDependencies": { | ||
"should": "^3.1.3", | ||
"mocha": "^1.17.1" | ||
} | ||
} |
@@ -1,4 +0,64 @@ | ||
callback-count | ||
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. | ||
#### Count callbacks before continuing, tiny control flow helper, allows dynamic counting. | ||
### Flow control | ||
```js | ||
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. | ||
```js | ||
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 | ||
```js | ||
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 | ||
```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 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4125
7
65
64
2