Skip to content

Commit

Permalink
fix: extract noop everywhere (#3559) (#3727)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak authored Oct 13, 2024
1 parent fd32a55 commit 5415911
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/dispatcher/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ let deprecatedInterceptorWarned = false

const kClosedResolve = Symbol('kClosedResolve')

const noop = () => {}

function getPipelining (client) {
return client[kPipelining] ?? client[kHTTPContext]?.defaultPipelining ?? 1
}
Expand Down Expand Up @@ -442,7 +444,7 @@ async function connect (client) {
})

if (client.destroyed) {
util.destroy(socket.on('error', () => {}), new ClientDestroyedError())
util.destroy(socket.on('error', noop), new ClientDestroyedError())
return
}

Expand All @@ -453,7 +455,7 @@ async function connect (client) {
? await connectH2(client, socket)
: await connectH1(client, socket)
} catch (err) {
socket.destroy().on('error', () => {})
socket.destroy().on('error', noop)
throw err
}

Expand Down
4 changes: 3 additions & 1 deletion lib/dispatcher/proxy-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ function defaultFactory (origin, opts) {
return new Pool(origin, opts)
}

const noop = () => {}

class ProxyAgent extends DispatcherBase {
constructor (opts) {
super()
Expand Down Expand Up @@ -81,7 +83,7 @@ class ProxyAgent extends DispatcherBase {
servername: this[kProxyTls]?.servername || proxyHostname
})
if (statusCode !== 200) {
socket.on('error', () => {}).destroy()
socket.on('error', noop).destroy()
callback(new RequestAbortedError(`Proxy response (${statusCode}) !== 200 when HTTP Tunneling`))
}
if (opts.protocol !== 'https:') {
Expand Down

0 comments on commit 5415911

Please # to comment.