func newWatcher(s store.Store, opts store.QueryServiceOptions) *watcher { w := &watcher{stopCh: make(chan struct{}), done: make(chan struct{})} changes := make(chan data.ServiceChange) ctx, cancel := context.WithCancel(context.Background()) s.WatchServices(ctx, changes, daemon.NewErrorSink(), opts) go func() { defer close(w.done) for { select { case change := <-changes: w.changes = append(w.changes, change) case <-w.stopCh: cancel() return } } }() return w }