Permalink
Browse files

Testes/fixes.

  • Loading branch information...
1 parent fa8600a commit 567712107846b4f0273287eda81aea54a995c189 Chakrit Wichian committed Dec 20, 2011
Showing with 67 additions and 6 deletions.
  1. +1 −1 jam.js
  2. +23 −0 test-jam.js
  3. +6 −5 test-multi.js
  4. +37 −0 test-passing.js
View
2 jam.js
@@ -21,7 +21,7 @@
// delay kickoff until user finished adding functions.
clearTimeout(execTimeout);
- setTimeout(execOne, 0);
+ execTimeout = setTimeout(execOne, 0);
return queueOne;
};
View
@@ -0,0 +1,23 @@
+
+// test-jam.js - Test deferred JAMs
+(function() {
+
+ var J = require('./jam')
+ , util = require('util');
+
+ function vendJams(howMany) {
+ var jam = J(function() { util.log('Out of JAMs!'); this(); });
+
+ for (var i = howMany; i > 0; i--) (function(i) {
+ jam = jam(function() {
+ util.log('' + i + ' JAM(s) left!');
+ setTimeout(this, 1000);
+ });
+ })(i);
+
+ jam = jam(function() { util.log('No more JAMs left!'); this(); });
+ }
+
+ vendJams(5);
+
+})();
View
@@ -7,12 +7,13 @@
jam(function() {
jam(function() {
- jam(function() { util.log("JAM! THREE"); this(); })
- (function() { util.log("JAM! FOUR"); this(); })
- (function() { util.log("JAM! FIVE"); this(); });
+ jam(function() { util.log("JAM! ONE"); this(); })
+ (function() { util.log("JAM! TWO"); this(); })
+ (function() { util.log("JAM! THREE"); setTimeout(this, 3000); })
+ (this);
})
- (function() { util.log("JAM! ONE"); this(); })
- (function() { util.log("JAM! TWO"); this(); });
+ (function() { util.log("JAM! FOUR"); this(); })
+ (function() { util.log("JAM! FIVE"); this(); });
});
})();
View
@@ -0,0 +1,37 @@
+
+// test-passing.js - Test passing JAMs around
+(function() {
+
+ var J = require('./jam')
+ , util = require('util');
+
+ function instruct(time, txt) { return function(jam) {
+ util.log(txt);
+ setTimeout(this, time);
+ }; }
+
+ function instruct(time, txt) {
+ return function(jam) {
+ return jam(function() {
+ util.log(txt);
+ setTimeout(this, time);
+ });
+ };
+ }
+
+ // sandwich making instructions
+ var growWheat = instruct(3000, 'growing wheats...')
+ , makeBread = instruct(1000, 'making breads...')
+ , sliceBread = instruct(500, 'slicing breads...')
+ , pasteJams = instruct(2000, 'pasting jams...')
+ , coupleEm = instruct(200, 'couple em together...');
+
+ var sandwich = J;
+ sandwich = growWheat(sandwich);
+ sandwich = makeBread(sandwich);
+ sandwich = sliceBread(sandwich);
+ sandwich = pasteJams(sandwich);
+ sandwich = coupleEm(sandwich);
+ sandwich(function() { util.log("YUM!"); });
+
+})();

0 comments on commit 5677121

Please sign in to comment.