Skip to content

Commit

Permalink
improved
Browse files Browse the repository at this point in the history
  • Loading branch information
joy999 committed Oct 27, 2023
1 parent a3233e8 commit 6575e8e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
8 changes: 7 additions & 1 deletion contrib/registry/nacos/nacos_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ package nacos
import (
"context"

"github.com/gogf/gf/v2/errors/gcode"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/net/gsvc"
"github.com/joy999/nacos-sdk-go/model"
)
Expand Down Expand Up @@ -38,7 +40,11 @@ func newWatcher(ctx context.Context) *Watcher {
// Proceed proceeds watch in blocking way.
// It returns all complete services that watched by `key` if any change.
func (w *Watcher) Proceed() (services []gsvc.Service, err error) {
e := <-w.event
e, ok := <-w.event
if !ok || e == nil {
err = gerror.NewCode(gcode.CodeNil)
return
}
if e.Err != nil {
err = e.Err
return
Expand Down
12 changes: 9 additions & 3 deletions contrib/registry/nacos/nacos_z_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,15 @@ func TestWatch(t *testing.T) {

var latestProceedResult atomic.Value
g.Go(ctx, func(ctx context.Context) {
res, err := watcher.Proceed()
t.AssertNil(err)
latestProceedResult.Store(res)
var (
err error
res []gsvc.Service
)
for err == nil {
res, err = watcher.Proceed()
t.AssertNil(err)
latestProceedResult.Store(res)
}
}, func(ctx context.Context, exception error) {
t.Fatal(exception)
})
Expand Down

0 comments on commit 6575e8e

Please sign in to comment.