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


Golang Worker.Wait方法代碼示例

本文整理匯總了Golang中github.com/juju/juju/worker.Worker.Wait方法的典型用法代碼示例。如果您正苦於以下問題:Golang Worker.Wait方法的具體用法?Golang Worker.Wait怎麽用?Golang Worker.Wait使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/juju/juju/worker.Worker的用法示例。


在下文中一共展示了Worker.Wait方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: waitShort

func waitShort(c *gc.C, w worker.Worker) error {
	done := make(chan error)
	go func() {
		done <- w.Wait()
	}()
	return waitForTimeout(c, done, coretesting.ShortWait)
}
開發者ID:felicianotech,項目名稱:juju,代碼行數:7,代碼來源:notify_test.go

示例2: CheckAlive

// CheckAlive Wait()s a short time for the supplied worker to return an error,
// and fails the test if it does. If it doesn't fail, it'll leave a goroutine
// running in the background, blocked on the worker's death; but that doesn't
// matter, because of *course* you correctly deferred a suitable Kill helper
// as soon as you created the worker in the first place. Right? Right.
//
// It doesn't Assert and is therefore suitable for use from any goroutine.
func CheckAlive(c *gc.C, w worker.Worker) {
	wait := make(chan error, 1)
	go func() {
		wait <- w.Wait()
	}()
	select {
	case <-time.After(aliveDelay):
	case err := <-wait:
		c.Errorf("expected alive worker; failed with %v", err)
	}
}
開發者ID:bac,項目名稱:juju,代碼行數:18,代碼來源:check.go

示例3: checkExitsWithError

func checkExitsWithError(c *gc.C, w worker.Worker, expectedErr string) {
	errCh := make(chan error)
	go func() {
		errCh <- w.Wait()
	}()
	select {
	case err := <-errCh:
		c.Check(err, gc.ErrorMatches, expectedErr)
	case <-time.After(coretesting.LongWait):
		c.Fatal("timed out waiting for worker to exit")
	}
}
開發者ID:AlexisBruemmer,項目名稱:juju,代碼行數:12,代碼來源:manifold_test.go

示例4: runWorkerAndWait

func runWorkerAndWait(c *gc.C, w worker.Worker, expectedErr string) {
	doneC := make(chan error)
	go func() {
		doneC <- w.Wait()
	}()
	select {
	case err := <-doneC:
		c.Assert(err, gc.ErrorMatches, expectedErr)
	case <-time.After(coretesting.LongWait):
		c.Fatal("timed out waiting for worker to stop")
	}
}
開發者ID:AlexisBruemmer,項目名稱:juju,代碼行數:12,代碼來源:worker_test.go

示例5: waitForExit

func waitForExit(c *gc.C, w worker.Worker) error {
	errCh := make(chan error)
	go func() {
		errCh <- w.Wait()
	}()
	select {
	case err := <-errCh:
		return err
	case <-time.After(coretesting.LongWait):
		c.Fatal("timed out waiting for worker to exit")
	}
	panic("can't get here")
}
開發者ID:makyo,項目名稱:juju,代碼行數:13,代碼來源:manifold_test.go

示例6: CheckKilled

// CheckKilled Wait()s for the supplied worker's error, which it returns for
// further analysis, or fails the test after a timeout expires. It doesn't
// Assert and is therefore suitable for use from any goroutine.
func CheckKilled(c *gc.C, w worker.Worker) error {
	wait := make(chan error, 1)
	go func() {
		wait <- w.Wait()
	}()
	select {
	case err := <-wait:
		return err
	case <-time.After(killTimeout):
		c.Errorf("timed out waiting for worker to stop")
		return errors.New("workertest: worker not stopping")
	}
}
開發者ID:bac,項目名稱:juju,代碼行數:16,代碼來源:check.go

示例7: checkNotExiting

func checkNotExiting(c *gc.C, w worker.Worker) {
	exited := make(chan bool)
	go func() {
		w.Wait()
		close(exited)
	}()

	select {
	case <-exited:
		c.Fatal("worker exited unexpectedly")
	case <-time.After(coretesting.ShortWait):
		// Worker didn't exit (good)
	}
}
開發者ID:makyo,項目名稱:juju,代碼行數:14,代碼來源:manifold_test.go

示例8: add

// add starts two goroutines that (1) kill the catacomb's tomb with any
// error encountered by the worker; and (2) kill the worker when the
// catacomb starts dying.
func (catacomb *Catacomb) add(w worker.Worker) {
	// We must wait for _both_ goroutines to exit in
	// arbitrary order depending on the order of the worker
	// and the catacomb shutting down.
	catacomb.wg.Add(2)
	go func() {
		defer catacomb.wg.Done()
		if err := w.Wait(); err != nil {
			catacomb.Kill(err)
		}
	}()
	go func() {
		defer catacomb.wg.Done()
		<-catacomb.tomb.Dying()
		worker.Stop(w)
	}()
}
開發者ID:bac,項目名稱:juju,代碼行數:20,代碼來源:catacomb.go

示例9: add

// add starts two goroutines that (1) kill the catacomb's tomb with any
// error encountered by the worker; and (2) kill the worker when the
// catacomb starts dying.
func (catacomb *Catacomb) add(w worker.Worker) {

	// The coordination via stopped is not reliably observable, and hence not
	// tested, but it's yucky to leave the second goroutine running when we
	// don't need to.
	stopped := make(chan struct{})
	catacomb.wg.Add(1)
	go func() {
		defer catacomb.wg.Done()
		defer close(stopped)
		if err := w.Wait(); err != nil {
			catacomb.Kill(err)
		}
	}()
	go func() {
		select {
		case <-stopped:
		case <-catacomb.tomb.Dying():
			w.Kill()
		}
	}()
}
開發者ID:exekias,項目名稱:juju,代碼行數:25,代碼來源:catacomb.go

示例10: stopWorker

func stopWorker(w worker.Worker) error {
	w.Kill()
	return w.Wait()
}
開發者ID:exekias,項目名稱:juju,代碼行數:4,代碼來源:machiner_test.go

示例11: kill

func kill(w worker.Worker) error {
	w.Kill()
	return w.Wait()
}
開發者ID:ktsakalozos,項目名稱:juju,代碼行數:4,代碼來源:manifold_test.go

示例12: TestFinishedWorker

func (s *FinishedSuite) TestFinishedWorker(c *gc.C) {
	// Pretty dumb test if interface is implemented
	// and Wait() returns nil.
	var fw worker.Worker = worker.FinishedWorker{}
	c.Assert(fw.Wait(), gc.IsNil)
}
開發者ID:howbazaar,項目名稱:juju,代碼行數:6,代碼來源:finishedworker_test.go


注:本文中的github.com/juju/juju/worker.Worker.Wait方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。