github.com/annwntech/go-micro/v2@v2.9.5/config/source/service/watcher.go (about)

     1  package service
     2  
     3  import (
     4  	"github.com/annwntech/go-micro/v2/config/source"
     5  	proto "github.com/annwntech/go-micro/v2/config/source/service/proto"
     6  )
     7  
     8  type watcher struct {
     9  	stream proto.Config_WatchService
    10  }
    11  
    12  func newWatcher(stream proto.Config_WatchService) (source.Watcher, error) {
    13  	return &watcher{stream: stream}, nil
    14  }
    15  
    16  func (w *watcher) Next() (*source.ChangeSet, error) {
    17  	var rsp proto.WatchResponse
    18  	err := w.stream.RecvMsg(&rsp)
    19  	if err != nil {
    20  		return nil, err
    21  	}
    22  	return toChangeSet(rsp.ChangeSet), nil
    23  }
    24  
    25  func (w *watcher) Stop() error {
    26  	return w.stream.Close()
    27  }