|
|
@ -46,19 +46,26 @@ func (d *Discovery) Watch(ctx context.Context, serviceName string) (registry.Wat |
|
|
|
return &watcher{ |
|
|
|
return &watcher{ |
|
|
|
Resolve: d.resolveBuild(serviceName), |
|
|
|
Resolve: d.resolveBuild(serviceName), |
|
|
|
serviceName: serviceName, |
|
|
|
serviceName: serviceName, |
|
|
|
|
|
|
|
cancelCtx: ctx, |
|
|
|
}, nil |
|
|
|
}, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type watcher struct { |
|
|
|
type watcher struct { |
|
|
|
*Resolve |
|
|
|
*Resolve |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cancelCtx context.Context |
|
|
|
serviceName string |
|
|
|
serviceName string |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (w *watcher) Next() ([]*registry.ServiceInstance, error) { |
|
|
|
func (w *watcher) Next() ([]*registry.ServiceInstance, error) { |
|
|
|
event := w.Resolve.Watch() |
|
|
|
event := w.Resolve.Watch() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
select { |
|
|
|
|
|
|
|
case <-event: |
|
|
|
// change event come
|
|
|
|
// change event come
|
|
|
|
<-event |
|
|
|
case <-w.cancelCtx.Done(): |
|
|
|
|
|
|
|
return nil, fmt.Errorf("watch context cancelled: %v", w.cancelCtx.Err()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.TODO(), 15*time.Second) |
|
|
|
ctx, cancel := context.WithTimeout(context.TODO(), 15*time.Second) |
|
|
|
defer cancel() |
|
|
|
defer cancel() |
|
|
|