-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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
http: refactor agent.destroy() #28596
Conversation
This change refactor the previous triple-nested loop and make it more readable by using iterators.
I'm guessing this probably doesn't need a benchmark but mentioning it in case I'm wrong about that. |
@nodejs/http |
@mscdex ^^^^^ |
1 similar comment
lib/_http_agent.js
Outdated
}; | ||
|
||
function destroySockets(sockets) { | ||
for (const setKey in sockets) { |
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.
briefer:
for (const setKey in sockets) { | |
for (const socket of Object.values(sockets).flat()) { |
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.
But probably also much less performant.
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.
in
changes the behavior though. Before, the prototype would not be checked but now it does.
I do not know why flat
was suggested. It should already be a flat array?
I think in this specific case it should be fine to use Object.values
, since it should not be a hot path to destroy the sockets.
lib/_http_agent.js
Outdated
}; | ||
|
||
function destroySockets(sockets) { | ||
for (const setKey in sockets) { |
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.
in
changes the behavior though. Before, the prototype would not be checked but now it does.
I do not know why flat
was suggested. It should already be a flat array?
I think in this specific case it should be fine to use Object.values
, since it should not be a hot path to destroy the sockets.
9430bf2
to
73da794
Compare
@BridgeAR Could you take another look? : ) |
This seems to be superseded by #30958. |
This change refactor the previous triple-nested loop and make it more readable by using iterators.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes