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 ( import (
"context" "context"
"fmt"
) )
type noopRegistry struct { type noopRegistry struct {
@ -54,7 +53,7 @@ func (n *noopRegistry) ListServices(ctx context.Context, opts ...ListOption) ([]
// Watch is used to watch for service changes // Watch is used to watch for service changes
func (n *noopRegistry) Watch(ctx context.Context, opts ...WatchOption) (Watcher, error) { 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 // String returns registry string representation
@ -62,6 +61,20 @@ func (n *noopRegistry) String() string {
return "noop" 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 // NewRegistry returns a new noop registry
func NewRegistry(opts ...Option) Registry { func NewRegistry(opts ...Option) Registry {
return &noopRegistry{opts: NewOptions(opts...)} return &noopRegistry{opts: NewOptions(opts...)}