-
Notifications
You must be signed in to change notification settings - Fork 565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: less async await #2463
chore: less async await #2463
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,40 +82,38 @@ class ProxyAgent extends DispatcherBase { | |
this[kClient] = clientFactory(resolvedUrl, { connect }) | ||
this[kAgent] = new Agent({ | ||
...opts, | ||
connect: async (opts, callback) => { | ||
connect: (opts, callback) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was unnecessary and made it less maintainable... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one was also questionable for me. But it should save a Promise? |
||
let requestedHost = opts.host | ||
if (!opts.port) { | ||
requestedHost += `:${defaultProtocolPort(opts.protocol)}` | ||
} | ||
try { | ||
const { socket, statusCode } = await this[kClient].connect({ | ||
origin, | ||
port, | ||
path: requestedHost, | ||
signal: opts.signal, | ||
headers: { | ||
...this[kProxyHeaders], | ||
host | ||
} | ||
}) | ||
if (statusCode !== 200) { | ||
socket.on('error', () => {}).destroy() | ||
callback(new RequestAbortedError('Proxy response !== 200 when HTTP Tunneling')) | ||
} | ||
if (opts.protocol !== 'https:') { | ||
callback(null, socket) | ||
return | ||
this[kClient].connect({ | ||
origin, | ||
port, | ||
path: requestedHost, | ||
signal: opts.signal, | ||
headers: { | ||
...this[kProxyHeaders], | ||
host | ||
} | ||
let servername | ||
if (this[kRequestTls]) { | ||
servername = this[kRequestTls].servername | ||
} else { | ||
servername = opts.servername | ||
} | ||
this[kConnectEndpoint]({ ...opts, servername, httpSocket: socket }, callback) | ||
} catch (err) { | ||
callback(err) | ||
} | ||
}).catch(callback) | ||
.then(({ socket, statusCode }) => { | ||
if (statusCode !== 200) { | ||
socket.on('error', () => { }).destroy() | ||
callback(new RequestAbortedError('Proxy response !== 200 when HTTP Tunneling')) | ||
} | ||
if (opts.protocol !== 'https:') { | ||
callback(null, socket) | ||
return | ||
} | ||
let servername | ||
if (this[kRequestTls]) { | ||
servername = this[kRequestTls].servername | ||
} else { | ||
servername = opts.servername | ||
} | ||
this[kConnectEndpoint]({ ...opts, servername, httpSocket: socket }, callback) | ||
}).catch(callback) | ||
} | ||
}) | ||
} | ||
|
@@ -136,14 +134,12 @@ class ProxyAgent extends DispatcherBase { | |
) | ||
} | ||
|
||
async [kClose] () { | ||
await this[kAgent].close() | ||
await this[kClient].close() | ||
[kClose] () { | ||
return Promise.all([this[kAgent].close, this[kClient].close]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Uzlopak @mcollina @KhafraDev ?: return Promise.all([this[kAgent].close(), this[kClient].close()]) And 👇🏻 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I searched for [kClose] and the places were it was was not awaited anyway. |
||
} | ||
|
||
async [kDestroy] () { | ||
await this[kAgent].destroy() | ||
await this[kClient].destroy() | ||
[kDestroy] () { | ||
return Promise.all([this[kAgent].destroy, this[kClient].destroy]) | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!!! This is wrong? needs a return at least?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was before not returning anything. So it is fire and forget? So why await anyway?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wasn't it at least informing the caller that the operation is done? I'm not sure where this is used, this can't possible cause racing conditions or break someone's tests?