You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
450 B
28 lines
450 B
3 years ago
|
package zookeeper
|
||
3 years ago
|
|
||
|
import (
|
||
|
"sync"
|
||
|
"sync/atomic"
|
||
|
|
||
|
"github.com/go-kratos/kratos/v2/registry"
|
||
|
)
|
||
|
|
||
|
type serviceSet struct {
|
||
|
serviceName string
|
||
|
watcher map[*watcher]struct{}
|
||
|
services *atomic.Value
|
||
|
lock sync.RWMutex
|
||
|
}
|
||
|
|
||
|
func (s *serviceSet) broadcast(ss []*registry.ServiceInstance) {
|
||
|
s.services.Store(ss)
|
||
|
s.lock.RLock()
|
||
|
defer s.lock.RUnlock()
|
||
|
for k := range s.watcher {
|
||
|
select {
|
||
|
case k.event <- struct{}{}:
|
||
|
default:
|
||
|
}
|
||
|
}
|
||
|
}
|