Make sure to call cancel on the context
This commit is contained in:
parent
f04c0a7069
commit
26d58865ab
|
@ -43,6 +43,7 @@ func keyWatch(params map[string]interface{}) (WatcherFunc, error) {
|
||||||
fn := func(p *Plan) (uint64, interface{}, error) {
|
fn := func(p *Plan) (uint64, interface{}, error) {
|
||||||
kv := p.client.KV()
|
kv := p.client.KV()
|
||||||
opts := makeQueryOptionsWithContext(p, stale)
|
opts := makeQueryOptionsWithContext(p, stale)
|
||||||
|
defer p.cancelFunc()
|
||||||
pair, meta, err := kv.Get(key, &opts)
|
pair, meta, err := kv.Get(key, &opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, nil, err
|
return 0, nil, err
|
||||||
|
@ -72,6 +73,7 @@ func keyPrefixWatch(params map[string]interface{}) (WatcherFunc, error) {
|
||||||
fn := func(p *Plan) (uint64, interface{}, error) {
|
fn := func(p *Plan) (uint64, interface{}, error) {
|
||||||
kv := p.client.KV()
|
kv := p.client.KV()
|
||||||
opts := makeQueryOptionsWithContext(p, stale)
|
opts := makeQueryOptionsWithContext(p, stale)
|
||||||
|
defer p.cancelFunc()
|
||||||
pairs, meta, err := kv.List(prefix, &opts)
|
pairs, meta, err := kv.List(prefix, &opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, nil, err
|
return 0, nil, err
|
||||||
|
@ -91,6 +93,7 @@ func servicesWatch(params map[string]interface{}) (WatcherFunc, error) {
|
||||||
fn := func(p *Plan) (uint64, interface{}, error) {
|
fn := func(p *Plan) (uint64, interface{}, error) {
|
||||||
catalog := p.client.Catalog()
|
catalog := p.client.Catalog()
|
||||||
opts := makeQueryOptionsWithContext(p, stale)
|
opts := makeQueryOptionsWithContext(p, stale)
|
||||||
|
defer p.cancelFunc()
|
||||||
services, meta, err := catalog.Services(&opts)
|
services, meta, err := catalog.Services(&opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, nil, err
|
return 0, nil, err
|
||||||
|
@ -110,6 +113,7 @@ func nodesWatch(params map[string]interface{}) (WatcherFunc, error) {
|
||||||
fn := func(p *Plan) (uint64, interface{}, error) {
|
fn := func(p *Plan) (uint64, interface{}, error) {
|
||||||
catalog := p.client.Catalog()
|
catalog := p.client.Catalog()
|
||||||
opts := makeQueryOptionsWithContext(p, stale)
|
opts := makeQueryOptionsWithContext(p, stale)
|
||||||
|
defer p.cancelFunc()
|
||||||
nodes, meta, err := catalog.Nodes(&opts)
|
nodes, meta, err := catalog.Nodes(&opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, nil, err
|
return 0, nil, err
|
||||||
|
@ -146,6 +150,7 @@ func serviceWatch(params map[string]interface{}) (WatcherFunc, error) {
|
||||||
fn := func(p *Plan) (uint64, interface{}, error) {
|
fn := func(p *Plan) (uint64, interface{}, error) {
|
||||||
health := p.client.Health()
|
health := p.client.Health()
|
||||||
opts := makeQueryOptionsWithContext(p, stale)
|
opts := makeQueryOptionsWithContext(p, stale)
|
||||||
|
defer p.cancelFunc()
|
||||||
nodes, meta, err := health.Service(service, tag, passingOnly, &opts)
|
nodes, meta, err := health.Service(service, tag, passingOnly, &opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, nil, err
|
return 0, nil, err
|
||||||
|
@ -179,6 +184,7 @@ func checksWatch(params map[string]interface{}) (WatcherFunc, error) {
|
||||||
fn := func(p *Plan) (uint64, interface{}, error) {
|
fn := func(p *Plan) (uint64, interface{}, error) {
|
||||||
health := p.client.Health()
|
health := p.client.Health()
|
||||||
opts := makeQueryOptionsWithContext(p, stale)
|
opts := makeQueryOptionsWithContext(p, stale)
|
||||||
|
defer p.cancelFunc()
|
||||||
var checks []*consulapi.HealthCheck
|
var checks []*consulapi.HealthCheck
|
||||||
var meta *consulapi.QueryMeta
|
var meta *consulapi.QueryMeta
|
||||||
var err error
|
var err error
|
||||||
|
@ -207,6 +213,7 @@ func eventWatch(params map[string]interface{}) (WatcherFunc, error) {
|
||||||
fn := func(p *Plan) (uint64, interface{}, error) {
|
fn := func(p *Plan) (uint64, interface{}, error) {
|
||||||
event := p.client.Event()
|
event := p.client.Event()
|
||||||
opts := makeQueryOptionsWithContext(p, false)
|
opts := makeQueryOptionsWithContext(p, false)
|
||||||
|
defer p.cancelFunc()
|
||||||
events, meta, err := event.List(name, &opts)
|
events, meta, err := event.List(name, &opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, nil, err
|
return 0, nil, err
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
package watch
|
package watch
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"context"
|
|
||||||
|
|
||||||
consulapi "github.com/hashicorp/consul/api"
|
consulapi "github.com/hashicorp/consul/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue