mirror of
https://github.com/fatedier/frp.git
synced 2025-06-16 16:28:23 +00:00
Compare commits
1 Commits
c97e2f9342
...
66125ab184
Author | SHA1 | Date | |
---|---|---|---|
|
66125ab184 |
@ -16,9 +16,10 @@ 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"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -181,18 +182,16 @@ 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 func() {
|
go lo.Try0(func() {
|
||||||
select {
|
select {
|
||||||
case <-ch:
|
case <-ch:
|
||||||
closeOnce.Do(func() {
|
close(out)
|
||||||
close(out)
|
|
||||||
})
|
|
||||||
case <-out:
|
case <-out:
|
||||||
}
|
}
|
||||||
}()
|
})
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user