func run(ctx *done.Context, key interface{}) { for { select { case <-ctx.Done(): fmt.Printf("%v goroutine done\n", key) ctx.OK() return } } }
func (p *pinger) heartbeat(ctx *done.Context) { for { select { case <-time.After(p.interval): p.online() case <-ctx.Done(): p.offline() ctx.OK() return } } }
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 } } }