feature/etcd #5

Merged
zhangdeman merged 5 commits from feature/etcd into master 2021-11-24 00:11:59 +08:00
7bef73334c 修复watcher取消后,监听协程仍在的问题
白茶清欢
2021-11-24 00:11:14 +08:00
Commit 5 of 5
Show all commits
+12 -1
View File
@@ -13,7 +13,7 @@ import (
"time"
)
// WatchKey 监听key的变化
// WatchKey 监听key的变化,永久监听
//
// Author : go_developer@163.com<白茶清欢>
//
@@ -26,6 +26,7 @@ func WatchKey(ctx context.Context, watchKey string, callbackFunc WatcherHandler)
if nil == ctx {
ctx = context.Background()
}
rch := Client.Watch(ctx, watchKey) // <-chan WatchResponse
for watchResp := range rch {
for _, ev := range watchResp.Events {
@@ -47,6 +48,11 @@ func WatchKeyWithCancel(ctx context.Context, watchKey string, callbackFunc Watch
if nil == ctx {
ctx = context.Background()
}
var (
cancelFunc context.CancelFunc
)
ctx, cancelFunc = context.WithCancel(ctx)
defer cancelFunc()
rch := Client.Watch(context.Background(), watchKey) // <-chan WatchResponse
@@ -92,6 +98,11 @@ func WatchKeyOnce(ctx context.Context, watchKey string, callbackFunc WatcherHand
if nil == ctx {
ctx = context.Background()
}
var (
cancelFunc context.CancelFunc
)
ctx, cancelFunc = context.WithCancel(ctx)
defer cancelFunc()
rch := Client.Watch(ctx, watchKey) // <-chan WatchResponse
select {
case <-time.After(timeout):
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.