Add comments and lightly refactor to improve clarity #47904
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
See (painful) discussion on #47892 (comment). Having invested the brainpower in figuring out what's going on, I decided I should add some comments to help future developers (most likely future me), and rename a few things to maybe make things slightly clearer.
In general, the
shutdownTasks.add(doTheAction)pattern confuses me every time I hit it, because I assumedoTheActionis producing something which happens at shutdown. That's sort of true, but it misses the massive side effect ofdoTheActionhappening now. So thedoTheActionmethod name is referring to what's happening now, not what's happening at shutdown, even though it's wrapped inshutdownTasks.add. The names and structure all just end up being a bit misleading. I don't see an alternative to the pattern, though. I guess you could pass the shutdownTasks in to the method, and then it would be self-cleaning. That's no good for the case where we do cleanup in afinallyblock, though.