Permalink
Browse files

[fix] general fix of async flow

  • Loading branch information...
AndreasMadsen committed Mar 5, 2012
1 parent b1bb1bb commit 647a09c8261d76682e1cf50d3b5e7735b40feb26
Showing with 28 additions and 2 deletions.
  1. +3 −1 lib/core/create.js
  2. +22 −0 lib/core/inform.js
  3. +3 −1 lib/module.js
View
@@ -30,6 +30,7 @@
// start proxy server
exports.startProxy(function (error, intercom) {
+ console.log(error + " :: " + intercom);
if (error !== null) {
callback(error, null);
return;
@@ -76,12 +77,13 @@
output: config.configuration.output
}
}, function (err) {
- if (err) {
+ if (err !== null) {
callback(err);
return;
}
// start continusely try connection
+ console.log('continusely try connection');
tryConnect();
});
};
View
@@ -15,6 +15,10 @@
exports.intercom = null;
+ /**
+ * Open intercom
+ * callback will be called with arguments (null, null) if the channel is closed
+ */
exports.open = function (cb) {
if (exports.remote) {
cb(null, exports.remote);
@@ -31,6 +35,7 @@
// we will assume that ECONNREFUSED or ENOENT mean that the proxy server isn't open
var errorHandler = function (error) {
+ console.log(error.code);
if (error.code === 'ECONNREFUSED' || error.code === 'ENOENT') {
callback(null);
return;
@@ -56,4 +61,21 @@
requester.connect('TCP', common.socketPath);
};
+ /**
+ * we may assume that the intercom has been opened
+ */
+ // setup remote
+ exports.setup = function (callback) {
+ exports.intercom.remote.setup(config.configuration, function () {
+ callback(this.error || null);
+ });
+ };
+
+ // add a proxy to remote
+ exports.addProxy = function (host, address, callback) {
+ exports.intercom.remote.addProxy({ host: host, address: address }, function () {
+ callback(this.error || null);
+ });
+ };
+
})();
View
@@ -37,7 +37,8 @@
* setup progress tracker
*/
progress = tracker(function () {
- inform.setup(vhost.domain, vhost.address, function (error) {
+ console.log('tracker done');
+ inform.addProxy(vhost.domain, vhost.address, function (error) {
if (error !== null) {
vhost.emit('error', error);
return;
@@ -93,6 +94,7 @@
//search for configuration file
if (progress.get('config-search') === false) {
+ progress.set('config-search');
config.parser.search();
}
};

0 comments on commit 647a09c

Please sign in to comment.