-
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 #2464
chore: less async await #2464
Changes from 3 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 |
---|---|---|
|
@@ -1807,11 +1807,11 @@ async function httpNetworkFetch ( | |
async start (controller) { | ||
fetchParams.controller.controller = controller | ||
}, | ||
async pull (controller) { | ||
await pullAlgorithm(controller) | ||
pull (controller) { | ||
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. cc: @KhafraDev 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. the streams spec will wrap this in a promise, so it does nothing |
||
return pullAlgorithm(controller) | ||
}, | ||
async cancel (reason) { | ||
await cancelAlgorithm(reason) | ||
cancel (reason) { | ||
return cancelAlgorithm(reason) | ||
} | ||
}, | ||
{ | ||
|
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. I think this is unnecessary change 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. tbh. This is for discussing. I agree this is reducing the maintainability. I am unsure if we save one Promise by this. |
||
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]) | ||
Uzlopak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
async [kDestroy] () { | ||
await this[kAgent].destroy() | ||
await this[kClient].destroy() | ||
[kDestroy] () { | ||
return Promise.all([this[kAgent].destroy, this[kClient].destroy]) | ||
Uzlopak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
|
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 might hide it from the stacktrace, not sure the attempt is to keep that function hidden as is part of the
RedeableStream
API and can be helpful while debugging.