Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

v0.1 implemented.

  • Loading branch information...
commit 813d4356fe8e74ac929c42a45840cd095bbb2e6e 1 parent 1ec777c
@chakrit authored
Showing with 47 additions and 0 deletions.
  1. +34 −0 jam.js
  2. +13 −0 test.js
View
34 jam.js
@@ -0,0 +1,34 @@
+
+// jam.js - Let's JAM!! X-D
+(function(undefined) {
+
+ var JAM = function(firstFunc) {
+ var queue = [firstFunc]
+ , execTimeout;
+
+ // continuation iterator, core continuation engine
+ var execOne = function() {
+ if (queue.length === 0) return;
+
+ // call the next function in queue with
+ // `this` set to this very function
+ queue.shift().apply(execOne, arguments);
+ };
+
+ // jam function queue processor
+ var queueOne = function(next) {
+ queue.push(next);
+
+ // delay kickoff until user finished adding functions.
+ clearTimeout(execTimeout);
+ setTimeout(execOne, 0);
+ return queueOne;
+ };
+
+ execTimeout = setTimeout(execOne, 0);
+ return queueOne;
+ };
+
+ module.exports = JAM;
+
+})();
View
13 test.js
@@ -0,0 +1,13 @@
+
+// test.js - test that JAM works
+(function() {
+
+ var jam = require('./jam')
+ , util = require('util');
+
+ jam(function(_) { console.log('one'); this('two'); })
+ (function(x) { console.log(x); this(); })
+ (function() { console.log('three'); this('fo', 'ur'); })
+ (function(y, z) { console.log(y + z); this(); });
+
+})();
Please sign in to comment.
Something went wrong with that request. Please try again.