-
Notifications
You must be signed in to change notification settings - Fork 90
Check if channel receive will succeed using len instead of a select statement. #292
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1194,16 +1194,19 @@ func (t tokenProcessor) nextToken() (tokenStruct, error) { | |
| // prioritize it over cancellation channel | ||
| select { | ||
| case tok, more := <-t.tokChan: | ||
| err, more := tok.(error) | ||
| if more { | ||
| t.sess.LogF(t.ctx, msdsn.LogDebug, "nextToken returned an error:"+err.Error()) | ||
| // this is an error and not a token | ||
| return nil, err | ||
| err, ok := tok.(error) | ||
| if ok { | ||
| t.sess.LogF(t.ctx, msdsn.LogDebug, "nextToken returned an error:"+err.Error()) | ||
| // this is an error and not a token | ||
| return nil, err | ||
| } else { | ||
| return tok, nil | ||
| } | ||
| } else { | ||
| return tok, nil | ||
| return nil, nil | ||
| } | ||
| default: | ||
| // there are no tokens on the channel, will need to wait | ||
| } | ||
|
Comment on lines
1195
to
1210
|
||
|
|
||
| select { | ||
|
|
||
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.
The comment explaining the default case behavior was removed. The original comment "there are no tokens on the channel, will need to wait" accurately describes what happens when the default case executes (the code falls through to the blocking select below). Consider restoring this comment for clarity.