grpc-java asynchronous server implementation

856 views
Skip to first unread message

fron...@gmail.com

unread,
Sep 28, 2015, 5:16:31 AM9/28/15
to grpc.io
If I want to implement an asynchronous server, is it safe to pass StreamObserver received with the request to another thread and call onNext and onCompleted on it?

Is that the right way to go anyway?

Eric Anderson

unread,
Sep 28, 2015, 12:01:36 PM9/28/15
to fron...@gmail.com, grpc.io
On Mon, Sep 28, 2015 at 2:16 AM, <fron...@gmail.com> wrote:
If I want to implement an asynchronous server, is it safe to pass StreamObserver received with the request to another thread and call onNext and onCompleted on it?

Yes, it is safe to pass StreamObserver to another thread. Note that the object is not thread-safe, so if you may call methods on it from multiple threads simultaneously you should do your own locking/synchronization. But if you are just passing it to another thread and the current thread doesn't call methods on it past that point, everything should "just work."

Is that the right way to go anyway?

Yes, for fully-asynchronous processing we would expect you to start any I/O on the current thread and then call methods on StreamObserver from some other thread once the I/O completes.
Reply all
Reply to author
Forward
0 new messages