Skip to content

Commit

Permalink
fix: remove fast timers implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak committed Sep 5, 2024
1 parent 89a46dd commit 5dcfaaa
Show file tree
Hide file tree
Showing 9 changed files with 7 additions and 727 deletions.
9 changes: 4 additions & 5 deletions lib/core/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const net = require('node:net')
const assert = require('node:assert')
const util = require('./util')
const { InvalidArgumentError, ConnectTimeoutError } = require('./errors')
const timers = require('../util/timers')

let tls // include tls conditionally since it is not always available

Expand Down Expand Up @@ -166,15 +165,15 @@ const setupConnectTimeout = process.platform === 'win32'

let s1 = null
let s2 = null
const timer = timers.setTimeout(() => {
const timer = setTimeout(() => {
// setImmediate is added to make sure that we prioritize socket error events over timeouts
s1 = setImmediate(() => {
// Windows needs an extra setImmediate probably due to implementation differences in the socket logic
s2 = setImmediate(() => onConnectTimeout(socket.deref()))
})
}, timeout)
return () => {
timers.clearTimeout(timer)
clearTimeout(timer)
clearImmediate(s1)
clearImmediate(s2)
}
Expand All @@ -185,14 +184,14 @@ const setupConnectTimeout = process.platform === 'win32'
}

let s1 = null
const timer = timers.setTimeout(() => {
const timer = setTimeout(() => {
// setImmediate is added to make sure that we prioritize socket error events over timeouts
s1 = setImmediate(() => {
onConnectTimeout(socket.deref())
})
}, timeout)
return () => {
timers.clearTimeout(timer)
clearTimeout(timer)
clearImmediate(s1)
}
}
Expand Down
7 changes: 3 additions & 4 deletions lib/dispatcher/client-h1.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
const assert = require('node:assert')
const util = require('../core/util.js')
const { channels } = require('../core/diagnostics.js')
const timers = require('../util/timers.js')
const {
RequestContentLengthMismatchError,
ResponseContentLengthMismatchError,
Expand Down Expand Up @@ -165,9 +164,9 @@ class Parser {
setTimeout (delay, type) {
this.timeoutType = type
if (delay !== this.timeoutValue) {
this.timeout && timers.clearTimeout(this.timeout)
this.timeout && clearTimeout(this.timeout)
if (delay) {
this.timeout = timers.setTimeout(onParserTimeout, delay, new WeakRef(this))
this.timeout = setTimeout(onParserTimeout, delay, new WeakRef(this))
// istanbul ignore else: only for jest
if (this.timeout.unref) {
this.timeout.unref()
Expand Down Expand Up @@ -293,7 +292,7 @@ class Parser {
this.llhttp.llhttp_free(this.ptr)
this.ptr = null

this.timeout && timers.clearTimeout(this.timeout)
this.timeout && clearTimeout(this.timeout)
this.timeout = null
this.timeoutValue = null
this.timeoutType = null
Expand Down
Loading

0 comments on commit 5dcfaaa

Please sign in to comment.