Return registry.ErrWatcherStopped when consul watcher stops.
The original code returns "result chan closed" errors.Error which does not carry higher semantics signal to downstream despite go-micro having a clearly defined Error for this behaviour. This commit fixes that and lets the downstream i.e. consumer of this code to act based on different errors.
This commit is contained in:
parent
7c4515d748
commit
73b0a0ed0e
@ -1,7 +1,6 @@
|
|||||||
package consul
|
package consul
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
@ -246,14 +245,16 @@ func (cw *consulWatcher) handle(idx uint64, data interface{}) {
|
|||||||
func (cw *consulWatcher) Next() (*registry.Result, error) {
|
func (cw *consulWatcher) Next() (*registry.Result, error) {
|
||||||
select {
|
select {
|
||||||
case <-cw.exit:
|
case <-cw.exit:
|
||||||
return nil, errors.New("result chan closed")
|
return nil, registry.ErrWatcherStopped
|
||||||
case r, ok := <-cw.next:
|
case r, ok := <-cw.next:
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("result chan closed")
|
return nil, registry.ErrWatcherStopped
|
||||||
}
|
}
|
||||||
return r, nil
|
return r, nil
|
||||||
}
|
}
|
||||||
return nil, errors.New("result chan closed")
|
// NOTE: This is a dead code path: e.g. it will never be reached
|
||||||
|
// as we return in all previous code paths never leading to this return
|
||||||
|
return nil, registry.ErrWatcherStopped
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cw *consulWatcher) Stop() {
|
func (cw *consulWatcher) Stop() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user