本文整理匯總了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)
}
}
}