本文整理匯總了Golang中github.com/juju/utils/voyeur.Watcher類的典型用法代碼示例。如果您正苦於以下問題:Golang Watcher類的具體用法?Golang Watcher怎麽用?Golang Watcher使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Watcher類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: mustNext
// mustNext waits for w's value to be set and returns it.
func mustNext(c *gc.C, w *voyeur.Watcher) (val interface{}) {
done := make(chan bool)
go func() {
c.Logf("mustNext %p", w)
ok := w.Next()
val = w.Value()
c.Logf("mustNext done %p, ok %v", w, ok)
done <- ok
}()
select {
case ok := <-done:
c.Assert(ok, jc.IsTrue)
return
case <-time.After(coretesting.LongWait):
c.Fatalf("timed out waiting for value to be set")
}
panic("unreachable")
}
示例2: mustNext
// mustNext waits for w's value to be set and returns it.
func mustNext(c *gc.C, w *voyeur.Watcher) (val interface{}) {
type voyeurResult struct {
ok bool
val interface{}
}
done := make(chan voyeurResult)
go func() {
c.Logf("mustNext %p", w)
ok := w.Next()
val = w.Value()
c.Logf("mustNext done %p, ok: %v, val: %#v", w, ok, val)
done <- voyeurResult{ok, val}
}()
select {
case result := <-done:
c.Assert(result.ok, jc.IsTrue)
return result.val
case <-time.After(coretesting.LongWait):
c.Fatalf("timed out waiting for value to be set")
}
panic("unreachable")
}