Permalink
Browse files

funstantiate the target instance

  • Loading branch information...
1 parent 6be4f25 commit ccf44e158ea6a1792a3c646b40b636032fcba7be @substack committed Sep 2, 2013
Showing with 11 additions and 6 deletions.
  1. +9 −5 index.js
  2. +2 −1 package.json
View
14 index.js
@@ -2,6 +2,7 @@ var upnode = require('upnode');
var seaport = require('seaport');
var EventEmitter = require('events').EventEmitter;
var pick = require('deck').pick;
+var funstance = require('funstance');
var airport = module.exports = function (ports) {
if (!ports || typeof ports.get !== 'function') {
@@ -60,25 +61,28 @@ Airport.prototype.connect = function (opts, fn) {
});
u.on('up', function () {
if (expired) return;
+ target.emit('up');
up = u;
});
u.on('down', function () {
if (expired) return;
+ target.emit('down');
up = null;
});
}
scan();
var queue = [];
- var target = function (cb) {
- if (up) up(cb)
- else queue.push(cb)
- };
+ var target = new EventEmitter;
target.close = function () {
if (up) up.close();
};
- return target;
+
+ return funstance(target, function (cb) {
+ if (up) up(cb)
+ else queue.push(cb)
+ });
};
Airport.prototype.listen = function () {
View
3 package.json
@@ -24,7 +24,8 @@
"dependencies" : {
"upnode" : "~0.4.3",
"deck" : "~0.0.4",
- "seaport" : "~1.5.3"
+ "seaport" : "~1.5.3",
+ "funstance": "~0.0.2"
},
"devDependencies" : {
"tap" : "~0.4.0",

0 comments on commit ccf44e1

Please sign in to comment.