Permalink
Browse files

Debugged tame rendezvous. added a bunch of test cases to make sure it…

…'s working properly, see tame_advanced.coffee
  • Loading branch information...
1 parent 01a488a commit b8acda8f05b0e5597f3621c055f5af996d0aa0b7 @maxtaco committed Dec 10, 2011
Showing with 51 additions and 14 deletions.
  1. +2 −2 lib/coffee-script/cake.js
  2. +1 −1 lib/coffee-script/nodes.js
  3. +5 −4 lib/coffee-script/tame.js
  4. +7 −5 src/tame.coffee
  5. +4 −2 test/tame.coffee
  6. +32 −0 test/tame_advanced.coffee
@@ -73,7 +73,7 @@
option: function(letter, flag, description) {
return switches.push([letter, flag, description]);
},
- invoke: function(name, cb) { /* TAMED */
+ invoke: function(name, cb) {
var t,
_this = this;
if (!(t = tasks[name])) missingTask(name);
@@ -98,7 +98,7 @@
}
});
- exports.run = function(cb) { /* TAMED */
+ exports.run = function(cb) {
var arg, args, __tame_k, _i, _len, _ref, _results, _while;
global.__originalDirname = fs.realpathSync('.');
process.chdir(cakefileDirectory(__originalDirname));
@@ -135,7 +135,7 @@
if (idt == null) idt = '';
if (name == null) name = this.constructor.name;
extras = "";
- if (this.tameNodeFlag) extras += "T";
+ if (this.tameNodeFlag) extras += "A";
if (this.tameLoopFlag) extras += "L";
if (this.cpsPivotFlag) extras += "P";
if (extras.length) extras = " (" + extras + ")";
@@ -82,7 +82,7 @@
this.completed = [];
this.waiters = [];
this.defer_id = 0;
- this.__tame_defers = this;
+ this[exports["const"].deferrals] = this;
}
RvId = (function() {
@@ -117,9 +117,10 @@
};
Rendezvous.prototype.id = function(i) {
- return {
- __tame_defers: new this.RvId(this, i)
- };
+ var ret;
+ ret = {};
+ ret[exports["const"].deferrals] = new RvId(this, i);
+ return ret;
};
Rendezvous.prototype._fulfill = function(id) {
View
@@ -7,7 +7,7 @@ exports.AstTamer = class AstTamer
transform: (x) ->
x.tameTransform()
-exports.const =
+exports.const =
k : "__tame_k"
ns: "tame"
Deferrals : "Deferrals"
@@ -63,9 +63,9 @@ class Rendezvous
@completed = []
@waiters = []
@defer_id = 0
- # This is a hack to work with the semantic desugaring of
- # 'defers' output by the coffee compiler.
- @__tame_defers = this
+ # This is a hack to work with the desugaring of
+ # 'defer' output by the coffee compiler.
+ @[exports.const.deferrals] = this
#-----------------------------------------
@@ -93,7 +93,9 @@ class Rendezvous
#-----------------------------------------
id: (i) ->
- { __tame_defers : new @RvId(this, i) }
+ ret = {}
+ ret[exports.const.deferrals] = new RvId(this, i)
+ ret
#-----------------------------------------
View
@@ -88,14 +88,16 @@ atest "parallel awaits with buggy classes", (cb) ->
increment: (wait, i, cb) ->
await setTimeout(defer(),wait)
@val += i
+ await setTimeout(defer(),wait)
+ @val += i
cb()
getVal: -> @val
- obj = new MyClass()
+ obj = new MyClass()
await
obj.increment 10, 1, defer()
obj.increment 20, 2, defer()
obj.increment 30, 4, defer()
v = obj.getVal()
- cb(v == 7, {})
+ cb(v == 14, {})
@@ -0,0 +1,32 @@
+
+tameRequire(skip)
+tame = require('../lib/coffee-script/coffee-script').tame;
+
+atest "rendezvous & windowing example", (cb) ->
+
+ slots = []
+ call = (i, cb) ->
+ slots[i] = 1
+ await setTimeout(defer(), 10*Math.random())
+ slots[i] |= 2
+ cb()
+
+ window = (n, window, cb) ->
+ rv = new tame.Rendezvous
+ nsent = 0
+ nrecv = 0
+ while nrecv < n
+ if nsent - nrecv < window && nsent < n
+ call nsent, rv.id(nsent).defer()
+ nsent++
+ else
+ await rv.wait defer(res)
+ slots[res] |= 4
+ nrecv++
+ cb()
+
+ await window 10, 3, defer()
+ res = true
+ for s in slots
+ res = false unless s == 7
+ cb(res, {})

0 comments on commit b8acda8

Please sign in to comment.