本文整理匯總了Golang中github.com/portworx/kvdb.Kvdb.WatchKey方法的典型用法代碼示例。如果您正苦於以下問題:Golang Kvdb.WatchKey方法的具體用法?Golang Kvdb.WatchKey怎麽用?Golang Kvdb.WatchKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/portworx/kvdb.Kvdb
的用法示例。
在下文中一共展示了Kvdb.WatchKey方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: watchKey
func watchKey(kv kvdb.Kvdb, t *testing.T) {
fmt.Println("\nwatchKey")
watchData := watchData{
t: t,
key: "tree/key1",
otherKey: "tree/otherKey1",
stop: "stop",
iterations: 2,
}
kv.Delete(watchData.key)
kv.Delete(watchData.otherKey)
// First create a key. We should not get update for this create.
_, err := kv.Create(watchData.otherKey, []byte("bar"), 0)
// Let the create operation finish and then start the watch
time.Sleep(time.Second)
err = kv.WatchKey(watchData.otherKey, 0, &watchData, watchFn)
if err != nil {
fmt.Printf("Cannot test watchKey: %v\n", err)
return
}
err = kv.WatchKey(watchData.key, 0, &watchData, watchFn)
if err != nil {
fmt.Printf("Cannot test watchKey: %v\n", err)
return
}
go watchUpdate(kv, &watchData)
for watchData.watchStopped == false {
time.Sleep(time.Millisecond * 100)
}
// Stop the second watch
atomic.SwapInt32(&watchData.whichKey, 0)
watchData.action = kvdb.KVCreate
_, err = kv.Create(watchData.otherKey, []byte(watchData.stop), 0)
}