Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

wrap example works finally

  • Loading branch information...
commit 436898850db3445a629ec5ba348481673c21b73a 1 parent 44496a1
@substack authored
Showing with 11 additions and 17 deletions.
  1. +5 −16 example/weak.js
  2. +6 −1 index.js
View
21 example/weak.js
@@ -4,15 +4,15 @@ var proto = require('../');
var s = (function () {
var cons = {
x : function (f, g) {
- setTimeout(function () { f(5) }, 2000);
- setTimeout(function () { g(6) }, 4000);
+ setTimeout(function () { f(5) }, 200);
+ setTimeout(function () { g(6) }, 400);
},
y : 555
};
return proto(cons, function (cb, id) {
var ref = weak(cb, function () {
console.log('s.cull(' + id + ')')
- //s.cull(id);
+ s.cull(id);
});
return function () {
var f = weak.get(ref);
@@ -21,16 +21,7 @@ var s = (function () {
});
})();
-var c = proto({}, function (cb, id) {
- var ref = weak(cb, function () {
- console.log('c.cull(' + id + ')')
- //c.cull(id);
- });
- return function () {
- var f = weak.get(ref);
- if (f) f.apply(this, arguments);
- };
-});
+var c = proto();
s.on('request', c.handle.bind(c));
c.on('request', s.handle.bind(s));
@@ -44,11 +35,9 @@ c.on('remote', function (remote) {
s.start();
c.start();
-/*
setTimeout(function () {
// switch on the garbage disposal to full blast:
var xs = [];
for (var i = 0; i < 1000 * 1000; i++) xs.push(function () {});
xs = [];
-}, 2500);
-*/
+}, 1000);
View
7 index.js
@@ -62,7 +62,12 @@ Proto.prototype.handle = function (req) {
var cb = function () {
self.request(id, [].slice.apply(arguments));
};
- self.callbacks.remote[id] = self.wrap ? self.wrap(cb, id) : cb;
+ if (self.wrap) {
+ var ref = self.wrap(cb, id);
+ self.callbacks.remote[id] = ref;
+ return cb;
+ }
+ else self.callbacks.remote[id] = cb;
}
return self.callbacks.remote[id];
});
Please sign in to comment.
Something went wrong with that request. Please try again.