always spawn a worker with the task it was supposed to complete#112
Merged
camdencheek merged 1 commit intosourcegraph:mainfrom May 3, 2023
Merged
always spawn a worker with the task it was supposed to complete#112camdencheek merged 1 commit intosourcegraph:mainfrom
camdencheek merged 1 commit intosourcegraph:mainfrom
Conversation
camdencheek
approved these changes
May 3, 2023
Member
camdencheek
left a comment
There was a problem hiding this comment.
Nice catch, and elegant solution!
Interestingly, I expected this to add an allocation for the closure, but TIL that closures do not allocate if all the captured variables are already on the heap.
Codecov Report
@@ Coverage Diff @@
## main #112 +/- ##
=======================================
Coverage 99.30% 99.30%
=======================================
Files 12 12
Lines 432 433 +1
=======================================
+ Hits 429 430 +1
Misses 3 3
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
For "unlimited" pools, in the original code:
If in between the call to
handle.Goand sending the task to the worker, another goroutine would callpool.Go, that task would "hijack" the newly created worker, causing the original send to block. This is undesirable behavior if the pool is unlimited.The solution was to add an
initialFuncto the worker, which will be executed before the worker starts waiting for new tasks. This ensures that a worker will first complete the task it was supposed to, then complete others.