Skip to content

Commit

Permalink
Testes/fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chakrit Wichian committed Dec 20, 2011
1 parent fa8600a commit 5677121
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 6 deletions.
2 changes: 1 addition & 1 deletion jam.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


// delay kickoff until user finished adding functions. // delay kickoff until user finished adding functions.
clearTimeout(execTimeout); clearTimeout(execTimeout);
setTimeout(execOne, 0); execTimeout = setTimeout(execOne, 0);
return queueOne; return queueOne;
}; };


Expand Down
23 changes: 23 additions & 0 deletions test-jam.js
Original file line number Original file line Diff line number Diff line change
@@ -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);

})();
11 changes: 6 additions & 5 deletions test-multi.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@


jam(function() { jam(function() {
jam(function() { jam(function() {
jam(function() { util.log("JAM! THREE"); this(); }) jam(function() { util.log("JAM! ONE"); this(); })
(function() { util.log("JAM! FOUR"); this(); }) (function() { util.log("JAM! TWO"); this(); })
(function() { util.log("JAM! FIVE"); this(); }); (function() { util.log("JAM! THREE"); setTimeout(this, 3000); })
(this);
}) })
(function() { util.log("JAM! ONE"); this(); }) (function() { util.log("JAM! FOUR"); this(); })
(function() { util.log("JAM! TWO"); this(); }); (function() { util.log("JAM! FIVE"); this(); });
}); });


})(); })();
37 changes: 37 additions & 0 deletions test-passing.js
Original file line number Original file line Diff line number Diff line change
@@ -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.