• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang worker.Worker类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/juju/juju/worker.Worker的典型用法代码示例。如果您正苦于以下问题:Golang Worker类的具体用法?Golang Worker怎么用?Golang Worker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Worker类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: gotStarted

// gotStarted updates the engine to reflect the creation of a worker. It must
// only be called from the loop goroutine.
func (engine *engine) gotStarted(name string, worker worker.Worker) {
	// Copy current info; check preconditions and abort the workers if we've
	// already been asked to stop it.
	info := engine.current[name]
	switch {
	case info.worker != nil:
		engine.tomb.Kill(errors.Errorf("fatal: unexpected %q manifold worker start", name))
		fallthrough
	case info.stopping, engine.isDying():
		logger.Debugf("%q manifold worker no longer required", name)
		worker.Kill()
	default:
		// It's fine to use this worker; update info and copy back.
		logger.Infof("%q manifold worker started", name)
		info.starting = false
		info.worker = worker
		engine.current[name] = info

		// Any manifold that declares this one as an input needs to be restarted.
		engine.bounceDependents(name)
	}
}
开发者ID:Pankov404,项目名称:juju,代码行数:24,代码来源:engine.go


示例11: stopWorker

func stopWorker(w worker.Worker) error {
	w.Kill()
	return w.Wait()
}
开发者ID:exekias,项目名称:juju,代码行数:4,代码来源:machiner_test.go


示例12: CheckKill

// CheckKill Kill()s the supplied worker and Wait()s for its 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 CheckKill(c *gc.C, w worker.Worker) error {
	w.Kill()
	return CheckKilled(c, w)
}
开发者ID:bac,项目名称:juju,代码行数:7,代码来源:check.go


示例13: kill

func kill(w worker.Worker) error {
	w.Kill()
	return w.Wait()
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:4,代码来源:manifold_test.go


示例14: 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类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang apiaddressupdater.NewAPIAddressUpdater函数代码示例发布时间:2022-05-23
下一篇:
Golang worker.Runner类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap