Skip to content

Commit

Permalink
src: reduce duplication in RegisterHandleCleanups
Browse files Browse the repository at this point in the history
This commit suggest using a lambda for the RegisterHandlerCleanup calls
in RegisterHandleCleanups.

The motivation is to reduce some duplication and to make it a little
easier to read as all of the calls pass in the same arguments, apart
from casting the uv handle.

PR-URL: #33421
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Zeyu Yang <[email protected]>
Reviewed-By: David Carlier <[email protected]>
  • Loading branch information
danbev authored and codebytere committed May 21, 2020
1 parent 02e8c14 commit ba69511
Showing 1 changed file with 9 additions and 24 deletions.
33 changes: 9 additions & 24 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -567,30 +567,15 @@ void Environment::RegisterHandleCleanups() {
});
};

RegisterHandleCleanup(
reinterpret_cast<uv_handle_t*>(timer_handle()),
close_and_finish,
nullptr);
RegisterHandleCleanup(
reinterpret_cast<uv_handle_t*>(immediate_check_handle()),
close_and_finish,
nullptr);
RegisterHandleCleanup(
reinterpret_cast<uv_handle_t*>(immediate_idle_handle()),
close_and_finish,
nullptr);
RegisterHandleCleanup(
reinterpret_cast<uv_handle_t*>(&idle_prepare_handle_),
close_and_finish,
nullptr);
RegisterHandleCleanup(
reinterpret_cast<uv_handle_t*>(&idle_check_handle_),
close_and_finish,
nullptr);
RegisterHandleCleanup(
reinterpret_cast<uv_handle_t*>(&task_queues_async_),
close_and_finish,
nullptr);
auto register_handle = [&](uv_handle_t* handle) {
RegisterHandleCleanup(handle, close_and_finish, nullptr);
};
register_handle(reinterpret_cast<uv_handle_t*>(timer_handle()));
register_handle(reinterpret_cast<uv_handle_t*>(immediate_check_handle()));
register_handle(reinterpret_cast<uv_handle_t*>(immediate_idle_handle()));
register_handle(reinterpret_cast<uv_handle_t*>(&idle_prepare_handle_));
register_handle(reinterpret_cast<uv_handle_t*>(&idle_check_handle_));
register_handle(reinterpret_cast<uv_handle_t*>(&task_queues_async_));
}

void Environment::CleanupHandles() {
Expand Down

0 comments on commit ba69511

Please sign in to comment.