Ai
1 Star 0 Fork 0

yzsunjianguo/common_pkg

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
watcher.go 642 Bytes
一键复制 编辑 原始数据 按行查看 历史
yzsunjianguo 提交于 2024-02-08 11:08 +08:00 . fix
package consul
import (
"context"
"gitee.com/yzsunjianguo/common_pkg/servicerd/registry"
)
type watcher struct {
event chan struct{}
set *serviceSet
// for cancel
ctx context.Context
cancel context.CancelFunc
}
func (w *watcher) Next() (services []*registry.ServiceInstance, err error) {
select {
case <-w.ctx.Done():
err = w.ctx.Err()
case <-w.event:
}
ss, ok := w.set.services.Load().([]*registry.ServiceInstance)
if ok {
services = append(services, ss...)
}
return //nolint
}
func (w *watcher) Stop() error {
w.cancel()
w.set.lock.Lock()
defer w.set.lock.Unlock()
delete(w.set.watcher, w)
return nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/yzsunjianguo/common_pkg.git
git@gitee.com:yzsunjianguo/common_pkg.git
yzsunjianguo
common_pkg
common_pkg
v1.0.1

搜索帮助