Permalink
Browse files

hub down server down test finally passes

  • Loading branch information...
1 parent ccf44e1 commit 966c89e0e33952b8f15bacfee13ad1e47160d27c @substack committed Sep 2, 2013
Showing with 8 additions and 2 deletions.
  1. +8 −2 index.js
View
@@ -39,22 +39,24 @@ Airport.prototype.connect = function (opts, fn) {
}
var role = opts.role;
var up = null;
+ var connected = undefined;
+ self.ports.on('connect', function () { connected = true });
+ self.ports.on('disconnect', function () { connected = false });
function scan () {
var ps = self.ports.query(role);
if (ps.length === 0) return setTimeout(scan, 1000);
var expired = false;
var timeout = setTimeout(function () {
- console.error('TIMED OUT');
expired = true;
scan();
}, 1000);
var s = pick(ps);
var u = upnode.connect(s);
u(function (ref) {
- clearTimeout(timeout);
if (expired) return;
+ clearTimeout(timeout);
queue.forEach(function (cb) { cb(ref) });
queue = [];
@@ -68,6 +70,10 @@ Airport.prototype.connect = function (opts, fn) {
if (expired) return;
target.emit('down');
up = null;
+ if (connected === false) {
+ expired = true;
+ scan();
+ }
});
}
scan();

0 comments on commit 966c89e

Please sign in to comment.