修复一次行监听为取消问题

This commit is contained in:
zhangdeman committed 2021-11-24 00:08:14 +08:00
1 parent 43cf6f27c9
commit c21e16138d
1 file changed
+6 -1
+6 -1
View File
@@ -24,13 +24,18 @@ func LeaseOnce(ctx context.Context, key string, val string, ttl int64) error {
if ttl <= 0 {
return errors.New("lease time must be more than 0")
}
if nil == ctx {
ctx = context.TODO()
ctx = context.Background()
}
var (
resp *clientv3.LeaseGrantResponse
err error
cancelFunc context.CancelFunc
)
ctx, cancelFunc = context.WithCancel(ctx)
defer cancelFunc()
// 创建一个5秒的租约
if resp, err = Client.Grant(ctx, ttl); err != nil {
return errors.New("lease grant error : " + err.Error())
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.