SendWithContext attempts to send a value to a channel, but returns early if the context is cancelled. This prevents goroutine deadlocks when the channel receiver has exited due to an error. Use this instead of bare channel sends (ch <- val) in goroutines to ensure proper cleanup when the migration
(ctx context.Context, ch chan<- T, val T)
| 1045 | // return err // context was cancelled |
| 1046 | // } |
| 1047 | func SendWithContext[T any](ctx context.Context, ch chan<- T, val T) error { |
| 1048 | select { |
| 1049 | case ch <- val: |
| 1050 | return nil |
| 1051 | case <-ctx.Done(): |
| 1052 | return ctx.Err() |
| 1053 | } |
| 1054 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…