MCPcopy Create free account
hub / github.com/wavetermdev/waveterm / DrainChannelSafe

Function DrainChannelSafe

pkg/util/utilfn/utilfn.go:1084–1101  ·  view source on GitHub ↗

DrainChannelSafe will drain a channel until it is empty or until a timeout is reached.

(ch <-chan T, debugName string)

Source from the content-addressed store, hash-verified

1082
1083// DrainChannelSafe will drain a channel until it is empty or until a timeout is reached.
1084func 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
1104func IsBinaryContent(data []byte) bool {

Callers 5

setServerDoneMethod · 0.92
AdaptOutputChToStreamFunction · 0.92
ReadFileStreamFunction · 0.92
WriterChanFunction · 0.92
fileListRunFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected