mirror of
https://github.com/tribufu/node-gamedig
synced 2026-06-01 09:42:41 +00:00
fix: registerRTT would break successful queries (#610)
* revert commit * revert core registerRTT * revert "revert commit" * making this simpler * changelog
This commit is contained in:
parent
d88f6cfca3
commit
60c3990c7c
2 changed files with 12 additions and 14 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
## To Be Released...
|
## To Be Released...
|
||||||
## 5.X.Y
|
## 5.X.Y
|
||||||
* Added Vintage Story support via the master server (#606)
|
* Added Vintage Story support via the master server (#606)
|
||||||
|
* Fixed `registerRtt` breaking successful queries if it didn't respond in the query timeout (#610)
|
||||||
* Added support for rFactor 2 (By @xCausxn #614)
|
* Added support for rFactor 2 (By @xCausxn #614)
|
||||||
|
|
||||||
## 4.3.2
|
## 4.3.2
|
||||||
|
|
|
||||||
|
|
@ -101,20 +101,17 @@ export default class Core extends EventEmitter {
|
||||||
async run (/** Results */ state) {}
|
async run (/** Results */ state) {}
|
||||||
|
|
||||||
/** Param can be a time in ms, or a promise (which will be timed) */
|
/** Param can be a time in ms, or a promise (which will be timed) */
|
||||||
async registerRtt (param) {
|
registerRtt (param) {
|
||||||
try {
|
if (param instanceof Promise) {
|
||||||
if (param instanceof Promise) {
|
const start = Date.now()
|
||||||
const start = Date.now()
|
param.then(() => {
|
||||||
await param
|
this.registerRtt(Date.now() - start)
|
||||||
await this.registerRtt(Date.now() - start)
|
}).catch((_) => {})
|
||||||
} else {
|
} else {
|
||||||
this.logger.debug(`Registered RTT: ${param}ms`)
|
this.logger.debug('Registered RTT: ' + param + 'ms')
|
||||||
if (this.shortestRTT === 0 || param < this.shortestRTT) {
|
if (this.shortestRTT === 0 || param < this.shortestRTT) {
|
||||||
this.shortestRTT = param
|
this.shortestRTT = param
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
|
||||||
this.logger.debug(`Error in promise: ${error}`)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -198,7 +195,7 @@ export default class Core extends EventEmitter {
|
||||||
socket.on('ready', resolve)
|
socket.on('ready', resolve)
|
||||||
socket.on('close', () => reject(new Error('TCP Connection Refused')))
|
socket.on('close', () => reject(new Error('TCP Connection Refused')))
|
||||||
})
|
})
|
||||||
await this.registerRtt(connectionPromise)
|
this.registerRtt(connectionPromise)
|
||||||
connectionTimeout = Promises.createTimeout(this.options.socketTimeout, 'TCP Opening')
|
connectionTimeout = Promises.createTimeout(this.options.socketTimeout, 'TCP Opening')
|
||||||
await Promise.race([
|
await Promise.race([
|
||||||
connectionPromise,
|
connectionPromise,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue