當前位置: 首頁>>代碼示例>>Golang>>正文


Golang state.NotifyWatcher類代碼示例

本文整理匯總了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;未經允許,請勿轉載。