Skip to content

Commit

Permalink
making this simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
CosminPerRam committed Aug 19, 2024
1 parent 1dd78cd commit 231e259
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions protocols/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,11 @@ export default class Core extends EventEmitter {

/** Param can be a time in ms, or a promise (which will be timed) */
registerRtt (param) {
if (param.then) {
if (param instanceof Promise) {
const start = Date.now()
param.then(() => {
const end = Date.now()
const rtt = end - start
this.registerRtt(rtt)
}).catch(() => {})
this.registerRtt(Date.now() - start)
}).catch((_) => {})
} else {
this.logger.debug('Registered RTT: ' + param + 'ms')
if (this.shortestRTT === 0 || param < this.shortestRTT) {
Expand Down Expand Up @@ -197,7 +195,7 @@ export default class Core extends EventEmitter {
socket.on('ready', resolve)
socket.on('close', () => reject(new Error('TCP Connection Refused')))
})
await this.registerRtt(connectionPromise)
this.registerRtt(connectionPromise)
connectionTimeout = Promises.createTimeout(this.options.socketTimeout, 'TCP Opening')
await Promise.race([
connectionPromise,
Expand Down

0 comments on commit 231e259

Please sign in to comment.