Skip to content

Commit

Permalink
lib: rewrite i-face introspection without promises
Browse files Browse the repository at this point in the history
PR-URL: #245
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Mykola Bilochub <nbelochub@gmail.com>
  • Loading branch information
tshemsedinov authored and belochub committed Jan 22, 2018
1 parent 4605959 commit 2c29675
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions lib/transport-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,23 @@ const newConnectAndInspectFn = (connFactory, transportClass) => {
const callback = common.extractCallback(options);
connect(appName, client, ...options, (error, connection) => {
if (error) return callback(error);

Promise.all(interfaces.map(name => new Promise((resolve, reject) => {
connection.inspectInterface(name, (error, proxy) => {
if (error) {
reject(error);
} else {
resolve(proxy);
const proxies = Object.create(null);
let errored = false;
const len = interfaces.length;
let count = 0;
interfaces.forEach(name => connection.inspectInterface(name,
(error, proxy) => {
if (!errored) {
count++;
if (error) {
errored = true;
return callback(error, connection);
}
proxies[name] = proxy;
if (count === len) callback(null, connection, proxies);
}
});
}))).then((proxies) => {
const api = proxies.reduce((acc, proxy, idx) => {
const name = interfaces[idx];
acc[name] = proxy;
return acc;
}, Object.create(null));
callback(null, connection, api);
}).catch((error) => {
callback(error, connection);
});
}
));
});
};
};
Expand Down

0 comments on commit 2c29675

Please sign in to comment.