本文整理匯總了Golang中github.com/ha/doozer.Conn.Wait方法的典型用法代碼示例。如果您正苦於以下問題:Golang Conn.Wait方法的具體用法?Golang Conn.Wait怎麽用?Golang Conn.Wait使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/ha/doozer.Conn
的用法示例。
在下文中一共展示了Conn.Wait方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: watch
func watch(conn *doozer.Conn, events chan doozer.Event, revs chan int64) {
for {
rev := <-revs
event, err := conn.Wait("/*", rev)
if err != nil {
panic("error waiting for event, bailing")
}
revs <- event.Rev + 1
events <- event
}
}
示例2: waitFor
func waitFor(cl *doozer.Conn, path string) {
var rev int64
for {
ev, err := cl.Wait(path, rev)
if err != nil {
panic(err)
}
if ev.IsSet() && len(ev.Body) > 0 {
break
}
rev = ev.Rev + 1
}
}
示例3: follow
func follow(st *store.Store, cl *doozer.Conn, rev int64, stop chan bool) {
for {
ev, err := cl.Wait("/**", rev)
if err != nil {
panic(err)
}
// store.Clobber is okay here because the event
// has already passed through another store
mut := store.MustEncodeSet(ev.Path, string(ev.Body), store.Clobber)
st.Ops <- store.Op{ev.Rev, mut}
rev = ev.Rev + 1
select {
case <-stop:
return
default:
}
}
}
示例4: wait
// wait waits on a changes for the fiven file starting at the given
// revision from the given doozer connection. It sends updated peer
// lists on the returned channel.
func wait(d *doozer.Conn, file string, rev *int64) chan []string {
c := make(chan []string, 1)
cur := *rev
go func() {
for {
// Wait for the change.
e, err := d.Wait(file, cur+1)
if err != nil {
log.Println("waiting failed (no longer watching):", err)
close(c)
return
}
// Update the revision and send the change on the channel.
atomic.CompareAndSwapInt64(rev, cur, e.Rev)
cur = e.Rev
c <- strings.Split(string(e.Body), " ")
}
}()
return c
}