本文整理汇总了Golang中launchpad/net/juju-core/state.Machine.Watch方法的典型用法代码示例。如果您正苦于以下问题:Golang Machine.Watch方法的具体用法?Golang Machine.Watch怎么用?Golang Machine.Watch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类launchpad/net/juju-core/state.Machine
的用法示例。
在下文中一共展示了Machine.Watch方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Watch
// Watch starts an NotifyWatcher for each given machine.
func (m *MachinerAPI) Watch(args params.Entities) (params.NotifyWatchResults, error) {
result := params.NotifyWatchResults{
Results: make([]params.NotifyWatchResult, len(args.Entities)),
}
if len(args.Entities) == 0 {
return result, nil
}
for i, entity := range args.Entities {
err := common.ErrPerm
if m.auth.AuthOwner(entity.Tag) {
var machine *state.Machine
machine, err = m.st.Machine(state.MachineIdFromTag(entity.Tag))
if err == nil {
watch := machine.Watch()
// 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.Results[i].NotifyWatcherId = m.resources.Register(watch)
} else {
err = watcher.MustErr(watch)
}
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
}
示例2: newMachineToolWaiter
func newMachineToolWaiter(m *state.Machine) *toolsWaiter {
w := m.Watch()
waiter := &toolsWaiter{
changes: make(chan struct{}, 1),
watcher: w,
tooler: m,
}
go func() {
for _ = range w.Changes() {
waiter.changes <- struct{}{}
}
close(waiter.changes)
}()
return waiter
}
示例3: waitMachine
func (s *ProvisionerSuite) waitMachine(c *C, m *state.Machine, check func() bool) {
w := m.Watch()
defer stop(c, w)
timeout := time.After(500 * time.Millisecond)
resync := time.After(0)
for {
select {
case <-w.Changes():
if check() {
return
}
case <-resync:
resync = time.After(50 * time.Millisecond)
s.State.StartSync()
case <-timeout:
c.Fatalf("machine %v wait timed out", m)
}
}
}
示例4: waitMachine
func (s *CommonProvisionerSuite) waitMachine(c *C, m *state.Machine, 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
w := m.Watch()
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.State.StartSync()
case <-timeout:
c.Fatalf("machine %v wait timed out", m)
}
}
}