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.
The timer channels are created with a buffer. Because we aren't reusing them, we don't need to worry about draining that channel; the internal goroutine will still be able to write to the buffer and exit gracefully, at which point the GC will clean it all up.
We do still need to call
Stop()
to tell the timer to clean up immediately, as otherwise it will run for its full duration which (in a tight loop) can cause timer goroutines to pile up.@rjeczalik I still think this is just a minor simplification that won't have any noticeable performance impact, but you were right in #41 that draining the channel is technically unnecessary.
cc @dnozdrin as you reported the initial memory issue with the timer goroutines piling up; as far as I can tell this should still be safe in that regard