mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcdserver/api/v3rpc: watch.go with events slice
This commit is contained in:
parent
8da6e76588
commit
8f03c600b5
@ -19,6 +19,7 @@ import (
|
||||
|
||||
pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
|
||||
"github.com/coreos/etcd/storage"
|
||||
"github.com/coreos/etcd/storage/storagepb"
|
||||
)
|
||||
|
||||
type watchServer struct {
|
||||
@ -61,15 +62,25 @@ func (ws *watchServer) Watch(stream pb.Watch_WatchServer) error {
|
||||
func sendLoop(stream pb.Watch_WatchServer, watcher storage.Watcher, closec chan struct{}) {
|
||||
for {
|
||||
select {
|
||||
case e, ok := <-watcher.Chan():
|
||||
case evs, ok := <-watcher.Chan():
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
err := stream.Send(&pb.WatchResponse{Event: &e})
|
||||
|
||||
// TODO: evs is []storagepb.Event type
|
||||
// either return []*storagepb.Event from storage package
|
||||
// or define protocol buffer with []storagepb.Event.
|
||||
events := make([]*storagepb.Event, len(evs))
|
||||
for i := range evs {
|
||||
events[i] = &evs[i]
|
||||
}
|
||||
|
||||
err := stream.Send(&pb.WatchResponse{Events: events})
|
||||
storage.ReportEventReceived()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
case <-closec:
|
||||
// drain the chan to clean up pending events
|
||||
for {
|
||||
|
Loading…
x
Reference in New Issue
Block a user