You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
func SendToChannel[T any](ctx context.Context, c chan<- T, e interface{}) bool {
select {
case c <- e.(T): // It will panic if e is not of type T or a type that can be converted to T.
return true
case <-ctx.Done():
close(c)
return false
}
}
I think we need to implement "case" priority control. If chan has a buffer, when "c<- e. (T)" and "<- ctx. Done()" both satisfy simultaneously, "select" will randomly execute one of them. What should our goal be?
After ctx is cancelled, "c <- e.(T)" can still be executed, and then "<-ctx.Done()" can be executed to close chan.
When ctx is cancelled, priority is given to execution, that is, "<-ctx.Done()" has a higher priority
The text was updated successfully, but these errors were encountered:
Just reviewed your code and left some comments: #140 (review)
Option 1 sounds good to me. We don't need to give a strong guarantee for the priority. If the SendToChannel returns true, that doesn't mean the ctx hasn't done.
func SendToChannel[T any](ctx context.Context, c chan<- T, e interface{}) bool {
select {
case c <- e.(T): // It will panic if
e
is not of typeT
or a type that can be converted toT
.return true
case <-ctx.Done():
close(c)
return false
}
}
I think we need to implement "case" priority control. If chan has a buffer, when "c<- e. (T)" and "<- ctx. Done()" both satisfy simultaneously, "select" will randomly execute one of them. What should our goal be?
The text was updated successfully, but these errors were encountered: