示例#1
0
func run(ctx *done.Context, key interface{}) {
	for {
		select {
		case <-ctx.Done():
			fmt.Printf("%v goroutine done\n", key)
			ctx.OK()
			return
		}
	}
}
示例#2
0
func (p *pinger) heartbeat(ctx *done.Context) {
	for {
		select {
		case <-time.After(p.interval):
			p.online()
		case <-ctx.Done():
			p.offline()
			ctx.OK()
			return
		}
	}
}
示例#3
0
func watchService(ctx *done.Context, api client.KeysAPI, space *Namespace) {
	dir := watchDir(space.name)
	opts := &client.WatcherOptions{Recursive: true}
	watcher := api.Watcher(dir, opts)

	log.Infof("watch %s start", dir)
	for {
		update(watcher, space)
		select {
		case <-ctx.Done():
			log.Infof("watch %s done", dir)
			ctx.OK()
			return
		default:
			continue
		}
	}
}