本文整理汇总了Golang中github.com/juju/juju/state.NotifyWatcher.Wait方法的典型用法代码示例。如果您正苦于以下问题:Golang NotifyWatcher.Wait方法的具体用法?Golang NotifyWatcher.Wait怎么用?Golang NotifyWatcher.Wait使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/juju/state.NotifyWatcher
的用法示例。
在下文中一共展示了NotifyWatcher.Wait方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}