mirror of
https://gitee.com/IrisVega/frp.git
synced 2024-11-01 22:31:29 +08:00
fix(backoff): close of closed out channel (#3871)
* fix: close of closed channel * feat: replace Try0 to std
This commit is contained in:
parent
2d67e2e0c6
commit
3540910879
@ -16,10 +16,9 @@ package wait
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/samber/lo"
|
|
||||||
|
|
||||||
"github.com/fatedier/frp/pkg/util/util"
|
"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 {
|
func MergeAndCloseOnAnyStopChannel[T any](upstreams ...<-chan T) <-chan T {
|
||||||
out := make(chan T)
|
out := make(chan T)
|
||||||
|
closeOnce := sync.Once{}
|
||||||
for _, upstream := range upstreams {
|
for _, upstream := range upstreams {
|
||||||
ch := upstream
|
ch := upstream
|
||||||
go lo.Try0(func() {
|
go func() {
|
||||||
select {
|
select {
|
||||||
case <-ch:
|
case <-ch:
|
||||||
close(out)
|
closeOnce.Do(func() {
|
||||||
|
close(out)
|
||||||
|
})
|
||||||
case <-out:
|
case <-out:
|
||||||
}
|
}
|
||||||
})
|
}()
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user