code: func (d *Discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) {
  	defer func() {
  		for _, tc := range d.treeCaches {
  			tc.Stop()
  		}
  		// Drain event channel in case the treecache leaks goroutines otherwise.
  		for range d.updates {
  		}
  		d.conn.Close()
  	}()
  
  	for {
  		select {
  		case <-ctx.Done():
  			return
  		case event := <-d.updates:
  			tg := &targetgroup.Group{
  				Source: event.Path,
  			}
  			if event.Data != nil {
  				labelSet, err := d.parse(*event.Data, event.Path)
  				if err == nil {
  					tg.Targets = []model.LabelSet{labelSet}
  					d.sources[event.Path] = tg
  				} else {
  					delete(d.sources, event.Path)
  				}
  			} else {
  				delete(d.sources, event.Path)
  			}
  			select {
  			case <-ctx.Done():
  				return
  			case ch <- []*targetgroup.Group{tg}:
  			}
  		}
  	}
  }
docs: // Run implements the Discoverer interface.