diff --git a/lib/transport-common.js b/lib/transport-common.js index 7a343167..05b96c8d 100644 --- a/lib/transport-common.js +++ b/lib/transport-common.js @@ -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); - }); + } + )); }); }; };