0
votes

I have a server-side streaming gRPC service that may have messages coming in very rapidly. A nice to have client feature would be to know there are more updates already queued by the time this onNext execution is ready to display in the UI, as I would simply display the next one instead.

    StreamObserver< Info > streamObserver = new StreamObserver< info >( )
    {

        @Override
        public void onNext( Info info )
        {
              doStuffForALittleWhile();
              if( !someHasNextFunction() )
                   render();
        }
    }

Is there some has next function or method of detection I'm unaware of?

2

2 Answers

1
votes

There's no API to determine if additional messages have been received, but not yet delivered to the application.

The client-side stub API (e.g., StreamObserver) is implemented using the more advanced ClientCall/ClientCall.Listener API. It does not provide any received-but-not-delivered hint.

Internally, gRPC processes messages lazily. gRPC waits until the application is ready for more messages (typically by returning from StreamObserver.onNext()) to try to decode another message. If it decodes another message then it will immediately begin delivering that message.

1
votes

One way would be to have a small, buffer with messages from onNext. That would let you should the current message, and then check to see if another has arrived in the mean time.