修复一次行监听为取消问题
This commit is contained in:
parent
43cf6f27c9
commit
c21e16138d
@ -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())
|
||||
|
Loading…
Reference in New Issue
Block a user