Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Feb 4, 2023
1 parent e36561e commit a1574b0
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ const fastNowInterval = setInterval(() => {

// TODO (perf): This can probably be optimized.
for (const timer of fastTimers) {
if (timer.expires && fastNow >= timer.expires) {
timer.expires = 0
onParserTimeout.call(timer.self)
if (timer.timeoutExpires && fastNow >= timer.timeoutExpires) {
timer.timeoutExpires = 0
onParserTimeout(timer)
}
}
}, 1e3)
Expand Down Expand Up @@ -440,8 +440,8 @@ class Parser {
this.ptr = this.llhttp.llhttp_alloc(constants.TYPE.RESPONSE)
this.client = client
this.socket = socket
this.timeout = null
this.timeoutValue = null
this.timeoutExpires = 0
this.timeoutValue = 0
this.timeoutType = null
this.statusCode = null
this.statusText = ''
Expand All @@ -465,33 +465,32 @@ class Parser {
this.timeoutType = type
if (value === this.timeoutValue) {
this.refreshTimeout()
} else {
this.timeoutValue = value
if (this.timeoutValue) {
if (!this.timeout) {
this.timeout = {
expires: fastNow + this.timeoutValue,
self: this
}
fastTimers.add(this.timeout)
}
this.timeout.expires = fastNow + this.timeoutValue
} else {
fastTimers.delete(this.timeout)
} else if (value) {
if (!this.timeoutValue) {
fastTimers.add(this)
}
this.timeoutExpires = fastNow + value
} else {
fastTimers.delete(this)
this.timeoutExpires = 0
}

this.timeoutValue = value
}

refreshTimeout () {
if (this.timeout) {
this.timeout.expires = fastNow + this.timeout.delay
if (this.timeoutValue) {
this.timeoutExpires = fastNow + this.timeoutValue
}
}

clearTimeout () {
if (this.timeout) {
fastTimers.delete(this.timeout)
if (this.timeoutExpires) {
fastTimers.delete(this)
}

this.timeoutExpires = 0
this.timeoutValue = 0
}

resume () {
Expand Down

0 comments on commit a1574b0

Please sign in to comment.