本文整理汇总了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)
}