mirror of
https://github.com/go-kratos/kratos.git
synced 2026-05-22 10:15:24 +02:00
optimize:chan bool to chan struct{} (#1648)
This commit is contained in:
@@ -88,10 +88,10 @@ logger:
|
||||
}
|
||||
fmt.Println("get value", name)
|
||||
|
||||
done := make(chan bool)
|
||||
done := make(chan struct{})
|
||||
err = c.Watch("logger.level", func(key string, value kconfig.Value) {
|
||||
fmt.Println(key, " value change", value)
|
||||
done <- true
|
||||
done <- struct{}{}
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -18,7 +18,7 @@ type watcher struct {
|
||||
groupName string
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
watchChan chan bool
|
||||
watchChan chan struct{}
|
||||
cli naming_client.INamingClient
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ func newWatcher(ctx context.Context, cli naming_client.INamingClient, serviceNam
|
||||
clusters: clusters,
|
||||
groupName: groupName,
|
||||
cli: cli,
|
||||
watchChan: make(chan bool, 1),
|
||||
watchChan: make(chan struct{}, 1),
|
||||
}
|
||||
w.ctx, w.cancel = context.WithCancel(ctx)
|
||||
|
||||
@@ -37,7 +37,7 @@ func newWatcher(ctx context.Context, cli naming_client.INamingClient, serviceNam
|
||||
Clusters: clusters,
|
||||
GroupName: groupName,
|
||||
SubscribeCallback: func(services []model.SubscribeService, err error) {
|
||||
w.watchChan <- true
|
||||
w.watchChan <- struct{}{}
|
||||
},
|
||||
})
|
||||
return w, e
|
||||
|
||||
@@ -63,7 +63,7 @@ func (b *builder) Build(target resolver.Target, cc resolver.ClientConn, opts res
|
||||
err error
|
||||
w registry.Watcher
|
||||
)
|
||||
done := make(chan bool, 1)
|
||||
done := make(chan struct{}, 1)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
go func() {
|
||||
w, err = b.discoverer.Watch(ctx, strings.TrimPrefix(target.URL.Path, "/"))
|
||||
|
||||
Reference in New Issue
Block a user