proxy/grpcproxy/watch_broadcast.go
func (wb *watchBroadcast) add(w *watcher) bool {
	wb.mu.Lock()
	defer wb.mu.Unlock()
	if wb.nextrev > w.nextrev || (wb.nextrev == 0 && w.nextrev != 0) {
		// wb is too far ahead, w will miss events
		// or wb is being established with a current watcher
		return false
	}
	if wb.responses == 0 {
		// Newly created; create event will be sent by etcd.
		wb.receivers[w] = struct{}{}
		return true
	}
	// already sent by etcd; emulate create event
	ok := w.post(&pb.WatchResponse{
		Header: &pb.ResponseHeader{
			// todo: fill in ClusterId
			// todo: fill in MemberId:
			Revision: w.nextrev,
			// todo: fill in RaftTerm:
		},
		WatchId: w.id,
		Created: true,
	})
	if !ok {
		return false
	}
	wb.receivers[w] = struct{}{}
	watchersCoalescing.Inc()

	return true
}
func (wb *watchBroadcast) add(w *watcher) bool {
	wb.mu.Lock()
	defer wb.mu.Unlock()
	if wb.nextrev > w.nextrev || (wb.nextrev == 0 && w.nextrev != 0) {
		// wb is too far ahead, w will miss events
		// or wb is being established with a current watcher
		return false
	}
	if wb.responses == 0 {
		// Newly created; create event will be sent by etcd.
		wb.receivers[w] = struct{}{}
		return true
	}
	// already sent by etcd; emulate create event
	ok := w.post(&pb.WatchResponse{
		Header: &pb.ResponseHeader{
			// todo: fill in ClusterId
			// todo: fill in MemberId:
			Revision: w.nextrev,
			// todo: fill in RaftTerm:
		},
		WatchId: w.id,
		Created: true,
	})
	if !ok {
		return false
	}
	wb.receivers[w] = struct{}{}
	watchersCoalescing.Inc()

	return true
}
func ( wb * watchBroadcast ) add ( w * watcher ) bool { wb . mu . Lock ( ) defer wb . mu . Unlock ( ) if wb . nextrev > w . nextrev || ( wb . nextrev == 0 && w . nextrev != 0 ) { // wb is too far ahead, w will miss events // or wb is being established with a current watcher return false } if wb . responses == 0 { // Newly created; create event will be sent by etcd. wb . receivers [ w ] = struct { } { } return true } // already sent by etcd; emulate create event ok := w . post ( & pb . WatchResponse { Header : & pb . ResponseHeader { // todo: fill in ClusterId // todo: fill in MemberId: Revision : w . nextrev , // todo: fill in RaftTerm: } , WatchId : w . id , Created : true , } ) if ! ok { return false } wb . receivers [ w ] = struct { } { } watchersCoalescing . Inc ( ) return true }
// add puts a watcher into receiving a broadcast if its revision at least
// meets the broadcast revision. Returns true if added.
add puts a watcher into receiving a broadcast if its revision at least meets the broadcast revision . Returns true if added .