fix(backoff): close of closed out channel (#3871)

* fix: close of closed channel

* feat: replace Try0 to std
This commit is contained in:
Remember 2023-12-21 11:43:42 +08:00 committed by GitHub
parent 2d67e2e0c6
commit 3540910879
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 6 deletions

View File

@ -16,10 +16,9 @@ package wait
import (
"math/rand"
"sync"
"time"
"github.com/samber/lo"
"github.com/fatedier/frp/pkg/util/util"
)
@ -182,16 +181,18 @@ func Until(f func(), period time.Duration, stopCh <-chan struct{}) {
func MergeAndCloseOnAnyStopChannel[T any](upstreams ...<-chan T) <-chan T {
out := make(chan T)
closeOnce := sync.Once{}
for _, upstream := range upstreams {
ch := upstream
go lo.Try0(func() {
go func() {
select {
case <-ch:
closeOnce.Do(func() {
close(out)
})
case <-out:
}
})
}()
}
return out
}