chore(contrib/registry/consul): repeated judgment <-c.ctx.Done() add notes

pull/2763/head
demoManito 2 years ago
parent f03f5f8988
commit 36d5c404f1
  1. 2
      contrib/registry/consul/client.go
  2. 7
      contrib/registry/consul/go.mod

@ -204,6 +204,8 @@ func (c *Client) Register(_ context.Context, svc *registry.ServiceInstance, enab
ticker := time.NewTicker(time.Second * time.Duration(c.healthcheckInterval)) ticker := time.NewTicker(time.Second * time.Duration(c.healthcheckInterval))
defer ticker.Stop() defer ticker.Stop()
for { for {
// NOTICE: the try-receive operation here is to try to exit the sender goroutine as early as possible.
// https://go101.org/article/channel-closing.html
select { select {
case <-c.ctx.Done(): case <-c.ctx.Done():
_ = c.cli.Agent().ServiceDeregister(svc.ID) _ = c.cli.Agent().ServiceDeregister(svc.ID)

@ -3,10 +3,13 @@ module github.com/go-kratos/kratos/contrib/registry/consul/v2
go 1.16 go 1.16
require ( require (
github.com/armon/go-metrics v0.3.10 // indirect
github.com/go-kratos/kratos/v2 v2.6.1 github.com/go-kratos/kratos/v2 v2.6.1
github.com/google/btree v1.0.0 // indirect
github.com/hashicorp/consul/api v1.19.1 github.com/hashicorp/consul/api v1.19.1
)
require (
github.com/google/btree v1.0.0 // indirect
github.com/armon/go-metrics v0.3.10 // indirect
github.com/hashicorp/go-hclog v0.14.1 // indirect github.com/hashicorp/go-hclog v0.14.1 // indirect
github.com/hashicorp/go-immutable-radix v1.3.0 // indirect github.com/hashicorp/go-immutable-radix v1.3.0 // indirect
github.com/hashicorp/go-msgpack v0.5.5 // indirect github.com/hashicorp/go-msgpack v0.5.5 // indirect

Loading…
Cancel
Save