本文整理汇总了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):
}
}
开发者ID:imoapps,项目名称:juju,代码行数:7,代码来源:meterstatus_test.go
示例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")
}
}
开发者ID:imoapps,项目名称:juju,代码行数:7,代码来源:meterstatus_test.go
示例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
}
开发者ID:bac,项目名称:juju,代码行数:23,代码来源:reboot.go
示例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
}
开发者ID:bac,项目名称:juju,代码行数:29,代码来源:watch.go
示例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)
}
}
}
开发者ID:bac,项目名称:juju,代码行数:22,代码来源:provisioner_test.go
示例6: stopWatcher
func stopWatcher(c *gc.C, w state.NotifyWatcher) {
err := w.Stop()
c.Check(err, gc.IsNil)
}
开发者ID:klyachin,项目名称:juju,代码行数:4,代码来源:environ_test.go
注:本文中的github.com/juju/juju/state.NotifyWatcher类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论