本文整理匯總了Golang中github.com/juju/juju/state.NotifyWatcher類的典型用法代碼示例。如果您正苦於以下問題:Golang NotifyWatcher類的具體用法?Golang NotifyWatcher怎麽用?Golang NotifyWatcher使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了NotifyWatcher類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: assertMeterStatusNotChanged
func assertMeterStatusNotChanged(c *gc.C, w state.NotifyWatcher) {
select {
case <-w.Changes():
c.Fatalf("unexpected event from watcher")
case <-time.After(testing.ShortWait):
}
}
示例2: assertMeterStatusChanged
func assertMeterStatusChanged(c *gc.C, w state.NotifyWatcher) {
select {
case <-w.Changes():
case <-time.After(testing.LongWait):
c.Fatalf("expected event from watcher by now")
}
}
示例3: WatchForRebootEvent
// WatchForRebootEvent starts a watcher to track if there is a new
// reboot request on the machines ID or any of its parents (in case we are a container).
func (r *RebootAPI) WatchForRebootEvent() (params.NotifyWatchResult, error) {
err := common.ErrPerm
var watch state.NotifyWatcher
var result params.NotifyWatchResult
if r.auth.AuthOwner(r.machine.Tag()) {
watch = r.machine.WatchForRebootEvent()
err = nil
// Consume the initial event. Technically, API
// calls to Watch 'transmit' the initial event
// in the Watch response. But NotifyWatchers
// have no state to transmit.
if _, ok := <-watch.Changes(); ok {
result.NotifyWatcherId = r.resources.Register(watch)
} else {
err = watcher.EnsureErr(watch)
}
}
result.Error = common.ServerError(err)
return result, nil
}
示例4: NewMultiNotifyWatcher
// NewMultiNotifyWatcher creates a NotifyWatcher that combines
// each of the NotifyWatchers passed in. Each watcher's initial
// event is consumed, and a single initial event is sent.
// Subsequent events are not coalesced.
func NewMultiNotifyWatcher(w ...state.NotifyWatcher) *MultiNotifyWatcher {
m := &MultiNotifyWatcher{
watchers: w,
changes: make(chan struct{}),
}
var wg sync.WaitGroup
wg.Add(len(w))
staging := make(chan struct{})
for _, w := range w {
// Consume the first event of each watcher.
<-w.Changes()
go func(w state.NotifyWatcher) {
defer wg.Done()
m.tomb.Kill(w.Wait())
}(w)
// Copy events from the watcher to the staging channel.
go copyEvents(staging, w.Changes(), &m.tomb)
}
go func() {
defer m.tomb.Done()
m.loop(staging)
wg.Wait()
}()
return m
}
示例5: waitForWatcher
func (s *CommonProvisionerSuite) waitForWatcher(c *gc.C, w state.NotifyWatcher, name string, check func() bool) {
// TODO(jam): We need to grow a new method on NotifyWatcherC
// that calls StartSync while waiting for changes, then
// waitMachine and waitHardwareCharacteristics can use that
// instead
defer stop(c, w)
timeout := time.After(coretesting.LongWait)
resync := time.After(0)
for {
select {
case <-w.Changes():
if check() {
return
}
case <-resync:
resync = time.After(coretesting.ShortWait)
s.BackingState.StartSync()
case <-timeout:
c.Fatalf("%v wait timed out", name)
}
}
}
示例6: stopWatcher
func stopWatcher(c *gc.C, w state.NotifyWatcher) {
err := w.Stop()
c.Check(err, gc.IsNil)
}