-
Notifications
You must be signed in to change notification settings - Fork 137
Queue all changes in order using non-blocking async queue #981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
@@ Coverage Diff @@
## main #981 +/- ##
==========================================
+ Coverage 61.51% 61.53% +0.01%
==========================================
Files 254 254
Lines 31494 31490 -4
==========================================
+ Hits 19373 19376 +3
+ Misses 10533 10527 -6
+ Partials 1588 1587 -1
... and 9 files with indirect coverage changes 🚀 New features to boost your workflow:
|
guillaumemichel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes sense!
| for range sws.changes.Len() { | ||
| select { | ||
| case next := <-sws.changes: | ||
| case next := <-sws.changes.Out(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gammazero you wrote the library so you probably know better.
Are there any benefits of doing like above?
changes := sws.changes.Out()
for range sws.changes.Len() {
select {
case next := <-changes:
...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe slightly? The function call should get inlined anyway, so is it worth the extra line of code? 🤷
It is possible for changes to get our of order when they are submitted by goroutines for non-blocking operations. Instead of goroutines, use an asynchronous queue to maintain order of events.
This may prevent provlems caused by mis-ordering of events shuch as connect and disconnect events.