mirror of https://github.com/status-im/consul.git
parent
067027230b
commit
238d430275
|
@ -335,7 +335,7 @@ func agentServiceWatch(params map[string]interface{}) (WatcherFunc, error) {
|
||||||
|
|
||||||
func makeQueryOptionsWithContext(p *Plan, stale bool) consulapi.QueryOptions {
|
func makeQueryOptionsWithContext(p *Plan, stale bool) consulapi.QueryOptions {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
p.cancelFunc = cancel
|
p.setCancelFunc(cancel)
|
||||||
opts := consulapi.QueryOptions{AllowStale: stale}
|
opts := consulapi.QueryOptions{AllowStale: stale}
|
||||||
switch param := p.lastParamVal.(type) {
|
switch param := p.lastParamVal.(type) {
|
||||||
case WaitIndexVal:
|
case WaitIndexVal:
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package watch
|
package watch
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
@ -148,6 +149,17 @@ func (p *Plan) shouldStop() bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Plan) setCancelFunc(cancel context.CancelFunc) {
|
||||||
|
p.stopLock.Lock()
|
||||||
|
defer p.stopLock.Unlock()
|
||||||
|
if p.shouldStop() {
|
||||||
|
// The watch is stopped and execute the new cancel func to stop watchFactory
|
||||||
|
cancel()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
p.cancelFunc = cancel
|
||||||
|
}
|
||||||
|
|
||||||
func (p *Plan) IsStopped() bool {
|
func (p *Plan) IsStopped() bool {
|
||||||
p.stopLock.Lock()
|
p.stopLock.Lock()
|
||||||
defer p.stopLock.Unlock()
|
defer p.stopLock.Unlock()
|
||||||
|
|
Loading…
Reference in New Issue