DrainChannelSafe will drain a channel until it is empty or until a timeout is reached.
(ch <-chan T, debugName string)
| 1082 | |
| 1083 | // DrainChannelSafe will drain a channel until it is empty or until a timeout is reached. |
| 1084 | func DrainChannelSafe[T any](ch <-chan T, debugName string) { |
| 1085 | drainTimeoutCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 1086 | go func() { |
| 1087 | defer cancel() |
| 1088 | outer: |
| 1089 | for { |
| 1090 | select { |
| 1091 | case <-drainTimeoutCtx.Done(): |
| 1092 | log.Printf("[error] timeout draining channel: %s\n", debugName) |
| 1093 | break outer |
| 1094 | case _, ok := <-ch: |
| 1095 | if !ok { |
| 1096 | return |
| 1097 | } |
| 1098 | } |
| 1099 | } |
| 1100 | }() |
| 1101 | } |
| 1102 | |
| 1103 | |
| 1104 | func IsBinaryContent(data []byte) bool { |
no outgoing calls
no test coverage detected