Skip to content

Commit 2442989

Browse files
authored
fix: remove async on [kClose] and [kDestroy], only return Promise (#4450)
1 parent aec609b commit 2442989

File tree

8 files changed

+43
-43
lines changed

8 files changed

+43
-43
lines changed

lib/dispatcher/agent.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,24 +110,24 @@ class Agent extends DispatcherBase {
110110
return dispatcher.dispatch(opts, handler)
111111
}
112112

113-
async [kClose] () {
113+
[kClose] () {
114114
const closePromises = []
115115
for (const { dispatcher } of this[kClients].values()) {
116116
closePromises.push(dispatcher.close())
117117
}
118118
this[kClients].clear()
119119

120-
await Promise.all(closePromises)
120+
return Promise.all(closePromises)
121121
}
122122

123-
async [kDestroy] (err) {
123+
[kDestroy] (err) {
124124
const destroyPromises = []
125125
for (const { dispatcher } of this[kClients].values()) {
126126
destroyPromises.push(dispatcher.destroy(err))
127127
}
128128
this[kClients].clear()
129129

130-
await Promise.all(destroyPromises)
130+
return Promise.all(destroyPromises)
131131
}
132132

133133
get stats () {

lib/dispatcher/client-h1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ function onParserTimeout (parser) {
760760
* @param {import('net').Socket} socket
761761
* @returns
762762
*/
763-
async function connectH1 (client, socket) {
763+
function connectH1 (client, socket) {
764764
client[kSocket] = socket
765765

766766
if (!llhttpInstance) {

lib/dispatcher/client-h2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function parseH2Headers (headers) {
7777
return result
7878
}
7979

80-
async function connectH2 (client, socket) {
80+
function connectH2 (client, socket) {
8181
client[kSocket] = socket
8282

8383
const session = http2.connect(client[kUrl], {

lib/dispatcher/client.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ class Client extends DispatcherBase {
317317
return this[kNeedDrain] < 2
318318
}
319319

320-
async [kClose] () {
320+
[kClose] () {
321321
// TODO: for H2 we need to gracefully flush the remaining enqueued
322322
// request and close each stream.
323323
return new Promise((resolve) => {
@@ -329,7 +329,7 @@ class Client extends DispatcherBase {
329329
})
330330
}
331331

332-
async [kDestroy] (err) {
332+
[kDestroy] (err) {
333333
return new Promise((resolve) => {
334334
const requests = this[kQueue].splice(this[kPendingIdx])
335335
for (let i = 0; i < requests.length; i++) {
@@ -444,8 +444,8 @@ async function connect (client) {
444444

445445
try {
446446
client[kHTTPContext] = socket.alpnProtocol === 'h2'
447-
? await connectH2(client, socket)
448-
: await connectH1(client, socket)
447+
? connectH2(client, socket)
448+
: connectH1(client, socket)
449449
} catch (err) {
450450
socket.destroy().on('error', noop)
451451
throw err

lib/dispatcher/env-http-proxy-agent.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,20 @@ class EnvHttpProxyAgent extends DispatcherBase {
4646
return agent.dispatch(opts, handler)
4747
}
4848

49-
async [kClose] () {
50-
await this[kNoProxyAgent].close()
51-
if (!this[kHttpProxyAgent][kClosed]) {
52-
await this[kHttpProxyAgent].close()
53-
}
54-
if (!this[kHttpsProxyAgent][kClosed]) {
55-
await this[kHttpsProxyAgent].close()
56-
}
49+
[kClose] () {
50+
return Promise.all([
51+
this[kNoProxyAgent].close(),
52+
!this[kHttpProxyAgent][kClosed] && this[kHttpProxyAgent].close(),
53+
!this[kHttpsProxyAgent][kClosed] && this[kHttpsProxyAgent].close()
54+
])
5755
}
5856

59-
async [kDestroy] (err) {
60-
await this[kNoProxyAgent].destroy(err)
61-
if (!this[kHttpProxyAgent][kDestroyed]) {
62-
await this[kHttpProxyAgent].destroy(err)
63-
}
64-
if (!this[kHttpsProxyAgent][kDestroyed]) {
65-
await this[kHttpsProxyAgent].destroy(err)
66-
}
57+
[kDestroy] (err) {
58+
return Promise.all([
59+
this[kNoProxyAgent].destroy(err),
60+
!this[kHttpProxyAgent][kDestroyed] && this[kHttpProxyAgent].destroy(err),
61+
!this[kHttpsProxyAgent][kDestroyed] && this[kHttpsProxyAgent].destroy(err)
62+
])
6763
}
6864

6965
#getProxyAgentForUrl (url) {

lib/dispatcher/h2c-client.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ class H2CClient extends DispatcherBase {
110110
return this.#client.dispatch(opts, handler)
111111
}
112112

113-
async [kClose] () {
114-
await this.#client.close()
113+
[kClose] () {
114+
return this.#client.close()
115115
}
116116

117-
async [kDestroy] () {
118-
await this.#client.destroy()
117+
[kDestroy] () {
118+
return this.#client.destroy()
119119
}
120120
}
121121

lib/dispatcher/pool-base.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,17 @@ class PoolBase extends DispatcherBase {
108108
return new PoolStats(this)
109109
}
110110

111-
async [kClose] () {
111+
[kClose] () {
112112
if (this[kQueue].isEmpty()) {
113-
await Promise.all(this[kClients].map(c => c.close()))
113+
return Promise.all(this[kClients].map(c => c.close()))
114114
} else {
115-
await new Promise((resolve) => {
115+
return new Promise((resolve) => {
116116
this[kClosedResolve] = resolve
117117
})
118118
}
119119
}
120120

121-
async [kDestroy] (err) {
121+
[kDestroy] (err) {
122122
while (true) {
123123
const item = this[kQueue].shift()
124124
if (!item) {
@@ -127,7 +127,7 @@ class PoolBase extends DispatcherBase {
127127
item.handler.onError(err)
128128
}
129129

130-
await Promise.all(this[kClients].map(c => c.destroy(err)))
130+
return Promise.all(this[kClients].map(c => c.destroy(err)))
131131
}
132132

133133
[kDispatch] (opts, handler) {

lib/dispatcher/proxy-agent.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ class Http1ProxyWrapper extends DispatcherBase {
8080
return this.#client[kDispatch](opts, handler)
8181
}
8282

83-
async [kClose] () {
83+
[kClose] () {
8484
return this.#client.close()
8585
}
8686

87-
async [kDestroy] (err) {
87+
[kDestroy] (err) {
8888
return this.#client.destroy(err)
8989
}
9090
}
@@ -220,14 +220,18 @@ class ProxyAgent extends DispatcherBase {
220220
}
221221
}
222222

223-
async [kClose] () {
224-
await this[kAgent].close()
225-
await this[kClient].close()
223+
[kClose] () {
224+
return Promise.all([
225+
this[kAgent].close(),
226+
this[kClient].close()
227+
])
226228
}
227229

228-
async [kDestroy] () {
229-
await this[kAgent].destroy()
230-
await this[kClient].destroy()
230+
[kDestroy] () {
231+
return Promise.all([
232+
this[kAgent].destroy(),
233+
this[kClient].destroy()
234+
])
231235
}
232236
}
233237

0 commit comments

Comments
 (0)