Exemple #1
0
// StreamHealth is part of the queryservice.QueryServer interface
func (q *query) StreamHealth(request *querypb.StreamHealthRequest, stream queryservicepb.Query_StreamHealthServer) (err error) {
	defer q.server.HandlePanic(&err)

	c := make(chan *querypb.StreamHealthResponse, 10)
	wg := sync.WaitGroup{}
	wg.Add(1)
	go func() {
		defer wg.Done()
		for shr := range c {
			// we send until the client disconnects
			if err := stream.Send(shr); err != nil {
				return
			}
		}
	}()

	id, err := q.server.StreamHealthRegister(c)
	if err != nil {
		close(c)
		wg.Wait()
		return err
	}
	wg.Wait()
	return q.server.StreamHealthUnregister(id)
}
Exemple #2
0
// StreamHealth is part of the queryservice.QueryServer interface
func (q *query) StreamHealth(request *querypb.StreamHealthRequest, stream queryservicepb.Query_StreamHealthServer) (err error) {
	defer q.server.HandlePanic(&err)

	c := make(chan *querypb.StreamHealthResponse, 10)

	id, err := q.server.StreamHealthRegister(c)
	if err != nil {
		close(c)
		return err
	}

	for shr := range c {
		// we send until the client disconnects
		if err := stream.Send(shr); err != nil {
			break
		}
	}

	return q.server.StreamHealthUnregister(id)
}