Permalink
Browse files

Only affect times on the callback if it's a number.

The other side of the connection also needs to dereference its references to the callback when a callback is only used once.  For now, I'm requiring .times on that callback as well, but this could work across the wire by sending a .cull or similar function.
  • Loading branch information...
1 parent e3598b8 commit 2c0a94fd77dd0d08b9657f7ef581f90eaeffbe1d @bog bog committed Aug 30, 2011
Showing with 12 additions and 4 deletions.
  1. +12 −4 index.js
View
@@ -78,6 +78,12 @@ var Session = exports.Session = function (id, wrapper) {
// for a particular id
wrapped[id] = function () {
self.request(id, [].slice.apply(arguments));
+ if (typeof wrapped[id].times == 'number') {
+ wrapped[id].times--;
+ if (wrapped[id].times == 0) {
+ delete wrapped[id];
+ }
+ }
};
}
return wrapped[id];
@@ -157,10 +163,12 @@ var Scrubber = exports.Scrubber = function () {
var id = cbId;
self.callbacks[id] = function() {
node.apply(this, [].slice.call(arguments));
- node.times--;
- if (node.times == 0) {
- delete self.callbacks[id];
- delete wrapped[wrapped.indexOf(node)];
+ if (typeof node.times == 'number') {
+ node.times--;
+ if (node.times == 0) {
+ delete self.callbacks[id];
+ delete wrapped[wrapped.indexOf(node)];
+ }
}
};
wrapped.push(node);

0 comments on commit 2c0a94f

Please sign in to comment.