mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-10 08:20:23 +00:00
ea86bf7d83
Bumps the k8s-dependencies group with 2 updates: [k8s.io/klog/v2](https://github.com/kubernetes/klog) and [sigs.k8s.io/controller-runtime](https://github.com/kubernetes-sigs/controller-runtime). Updates `k8s.io/klog/v2` from 2.120.0 to 2.120.1 - [Release notes](https://github.com/kubernetes/klog/releases) - [Changelog](https://github.com/kubernetes/klog/blob/main/RELEASE.md) - [Commits](https://github.com/kubernetes/klog/compare/v2.120.0...v2.120.1) Updates `sigs.k8s.io/controller-runtime` from 0.16.3 to 0.17.0 - [Release notes](https://github.com/kubernetes-sigs/controller-runtime/releases) - [Changelog](https://github.com/kubernetes-sigs/controller-runtime/blob/main/RELEASE.md) - [Commits](https://github.com/kubernetes-sigs/controller-runtime/compare/v0.16.3...v0.17.0) --- updated-dependencies: - dependency-name: k8s.io/klog/v2 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: k8s-dependencies - dependency-name: sigs.k8s.io/controller-runtime dependency-type: direct:production update-type: version-update:semver-minor dependency-group: k8s-dependencies ... Signed-off-by: dependabot[bot] <support@github.com>
39 lines
833 B
Go
39 lines
833 B
Go
package syncs
|
|
|
|
import (
|
|
"context"
|
|
"reflect"
|
|
"sync"
|
|
)
|
|
|
|
// MergeChans returns a channel that is closed when any of the input channels are signaled.
|
|
// The caller must call the returned CancelFunc to ensure no resources are leaked.
|
|
func MergeChans[T any](chans ...<-chan T) (<-chan T, context.CancelFunc) {
|
|
var once sync.Once
|
|
out := make(chan T)
|
|
cancel := make(chan T)
|
|
cancelFunc := func() {
|
|
once.Do(func() {
|
|
close(cancel)
|
|
})
|
|
<-out
|
|
}
|
|
cases := make([]reflect.SelectCase, len(chans)+1)
|
|
for i := range chans {
|
|
cases[i] = reflect.SelectCase{
|
|
Dir: reflect.SelectRecv,
|
|
Chan: reflect.ValueOf(chans[i]),
|
|
}
|
|
}
|
|
cases[len(cases)-1] = reflect.SelectCase{
|
|
Dir: reflect.SelectRecv,
|
|
Chan: reflect.ValueOf(cancel),
|
|
}
|
|
go func() {
|
|
defer close(out)
|
|
_, _, _ = reflect.Select(cases)
|
|
}()
|
|
|
|
return out, cancelFunc
|
|
}
|