Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: atsuya/done-criteria
base: c9a078a68a
...
head fork: atsuya/done-criteria
compare: 1edd1f6dba
  • 3 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
4 Makefile
View
@@ -4,12 +4,12 @@ TESTS = $(shell find test -name "*.test.js" -type f)
all: test-all
test-all:
- NODE_ENV=test ./node_modules/mocha/bin/mocha \
+ @NODE_ENV=test ./node_modules/mocha/bin/mocha \
--reporter $(REPORTER) \
$(TESTS)
one:
- NODE_ENV=test ./node_modules/mocha/bin/mocha \
+ @NODE_ENV=test ./node_modules/mocha/bin/mocha \
--reporter $(REPORTER) \
${FILE}
44 README.md
View
@@ -24,7 +24,7 @@ unnamed
var DoneCriteria = require('../lib/done-criteria')
, exit = false;
-var doneCriteria = new DoneCriteria(['unko', 'geri'], function() {
+var doneCriteria = new DoneCriteria(['unko', 'geri'], function(error) {
console.log('all done!');
exit = true;
});
@@ -46,7 +46,7 @@ loop();
This code results in:
```
-$ node examples/unnamed.js
+$ node examples/unnamed.js
not done yet...
not done yet...
not done yet...
@@ -72,7 +72,7 @@ var doneCriteria = new DoneCriteria(
, function(name) { console.log('%s is done', name); }
]
}
- , function() {
+ , function(error) {
console.log('all done!');
exit = true;
}
@@ -98,7 +98,7 @@ loop();
This code will result in:
```
-$ node examples/named.js
+$ node examples/named.js
not done yet...
not done yet...
eat is done
@@ -107,6 +107,42 @@ all done!
```
+count
+-----
+
+```
+var DoneCriteria = require('../lib/done-criteria')
+ , exit = false;
+
+var doneCriteria = new DoneCriteria(3, function(error) {
+ console.log('all done!');
+ exit = true;
+});
+
+setTimeout(function() { doneCriteria.done(); }, 200);
+setTimeout(function() { doneCriteria.done(); }, 400);
+setTimeout(function() { doneCriteria.done(); }, 600);
+
+var loop = function() {
+ if (exit) {
+ process.exit(0);
+ } else {
+ console.log('not done yet...');
+ setTimeout(loop, 500);
+ }
+};
+loop();
+```
+
+This code will result in:
+
+```
+$ node examples/count.js
+not done yet...
+not done yet...
+all done!
+```
+
License
========
21 examples/count.js
View
@@ -0,0 +1,21 @@
+var DoneCriteria = require('../lib/done-criteria')
+ , exit = false;
+
+var doneCriteria = new DoneCriteria(3, function(error) {
+ console.log('all done!');
+ exit = true;
+});
+
+setTimeout(function() { doneCriteria.done(); }, 200);
+setTimeout(function() { doneCriteria.done(); }, 400);
+setTimeout(function() { doneCriteria.done(); }, 600);
+
+var loop = function() {
+ if (exit) {
+ process.exit(0);
+ } else {
+ console.log('not done yet...');
+ setTimeout(loop, 500);
+ }
+};
+loop();
4 lib/done-criteria.js
View
@@ -23,4 +23,8 @@ DoneCriteria.prototype.done = function() {
}
};
+DoneCriteria.prototype.error = function(error) {
+ return this.callback(error);
+};
+
module.exports = DoneCriteria;
14 test/done-criteria.test.js
View
@@ -83,4 +83,18 @@ describe('done-criteria', function() {
setTimeout(function() { done(); }, 1500);
});
});
+
+ context('with errors', function() {
+ it('calls callback with error', function(done) {
+ var errorMessage = 'error message'
+ , doneCriteria = new DoneCriteria(['unko', 'geri'], function(error) {
+ helper.should.exist(error);
+ error.message.should.equal(errorMessage);
+ done();
+ });
+
+ doneCriteria.done('geri');
+ doneCriteria.error(new Error(errorMessage));
+ });
+ });
});

No commit comments for this range

Something went wrong with that request. Please try again.