|
|
@ -1,6 +1,7 @@ |
|
|
|
package apollo |
|
|
|
package apollo |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
|
|
|
|
"context" |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/go-kratos/kratos/v2/config" |
|
|
|
"github.com/go-kratos/kratos/v2/config" |
|
|
@ -66,11 +67,13 @@ func newWatcher(a *apollo, logger log.Logger) (config.Watcher, error) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
changeCh := make(chan []*config.KeyValue) |
|
|
|
changeCh := make(chan []*config.KeyValue) |
|
|
|
a.client.AddChangeListener(&customChangeListener{in: changeCh, logger: logger}) |
|
|
|
listener := &customChangeListener{in: changeCh, logger: logger} |
|
|
|
|
|
|
|
a.client.AddChangeListener(listener) |
|
|
|
|
|
|
|
|
|
|
|
return &watcher{ |
|
|
|
return &watcher{ |
|
|
|
out: changeCh, |
|
|
|
out: changeCh, |
|
|
|
cancelFn: func() { |
|
|
|
cancelFn: func() { |
|
|
|
|
|
|
|
a.client.RemoveChangeListener(listener) |
|
|
|
close(changeCh) |
|
|
|
close(changeCh) |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, nil |
|
|
|
}, nil |
|
|
@ -78,7 +81,11 @@ func newWatcher(a *apollo, logger log.Logger) (config.Watcher, error) { |
|
|
|
|
|
|
|
|
|
|
|
// Next will be blocked until the Stop method is called
|
|
|
|
// Next will be blocked until the Stop method is called
|
|
|
|
func (w *watcher) Next() ([]*config.KeyValue, error) { |
|
|
|
func (w *watcher) Next() ([]*config.KeyValue, error) { |
|
|
|
return <-w.out, nil |
|
|
|
kv, ok := <-w.out |
|
|
|
|
|
|
|
if !ok { |
|
|
|
|
|
|
|
return nil, context.Canceled |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return kv, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (w *watcher) Stop() error { |
|
|
|
func (w *watcher) Stop() error { |
|
|
|