registry/noop: implement noop watcher

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2020-11-13 14:50:57 +03:00
parent 37f7960f4a
commit c44a82a8cb

View File

@ -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...)}