add buffer to promise like channel #2011
Open
+2
−2
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.
PR Description
add buffer to promise like channel so main goroutine loop doesn't block
Which issue(s) this PR fixes
no issue, just performance improvement
Notes to the Reviewer
hey @mattdurham, I was reviewing usage of go-actor and just noticed this so I wanted to share it with you.
in
DoWork
caller is being notified after config gets updated. because this channel is not buffered this goroutine will get blocked because caller is also blocked at this point (it's waiting on response fromdone
channel). main loop will remain blocked until goroutine that made this request is resumed again (which can take time theoretically speaking).probably the best approach when implementing logic of
DoWork
(aka workers) is to never have it's code blocked unless it is blocked on reading data from inbound mailboxes - in other words blocked because it's waiting on work.in this case, this can be easily achieved by making
done
, promise like channel, to have buffer of size 1. this will ensure thatDoWork
can write to it without waiting on this goroutine to be ready.defer close(done)
was removed because it is unnecessary, after data transmission, this channel is no longer used so no one will care if this channel is closed or not - eventually it will be garbage collected.PR Checklist