From c44a82a8cbb5ca184eacfd66cac7134104ea6b49 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Fri, 13 Nov 2020 14:50:57 +0300 Subject: [PATCH] registry/noop: implement noop watcher Signed-off-by: Vasiliy Tolstov --- registry/noop.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/registry/noop.go b/registry/noop.go index 7c79126a..f6633c0a 100644 --- a/registry/noop.go +++ b/registry/noop.go @@ -2,7 +2,6 @@ package registry import ( "context" - "fmt" ) type noopRegistry struct { @@ -54,7 +53,7 @@ func (n *noopRegistry) ListServices(ctx context.Context, opts ...ListOption) ([] // Watch is used to watch for service changes func (n *noopRegistry) Watch(ctx context.Context, opts ...WatchOption) (Watcher, error) { - return nil, fmt.Errorf("not implemented") + return &noopWatcher{done: make(chan struct{}), opts: NewWatchOptions(opts...)}, nil } // String returns registry string representation @@ -62,6 +61,20 @@ func (n *noopRegistry) String() string { return "noop" } +type noopWatcher struct { + opts WatchOptions + done chan struct{} +} + +func (n *noopWatcher) Next() (*Result, error) { + <-n.done + return nil, ErrWatcherStopped +} + +func (n *noopWatcher) Stop() { + close(n.done) +} + // NewRegistry returns a new noop registry func NewRegistry(opts ...Option) Registry { return &noopRegistry{opts: NewOptions(opts...)}