Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New method StreamObserver.complete(value) for unary RPC #10957

Open
panchenko opened this issue Feb 26, 2024 · 2 comments
Open

New method StreamObserver.complete(value) for unary RPC #10957

panchenko opened this issue Feb 26, 2024 · 2 comments

Comments

@panchenko
Copy link
Contributor

I think unary RPCs are used quite often, then in the service implementation we have to write 2 lines:

responseObserver.onNext(result);
responseObserver.onCompleted();

It seems logical to introduce a default method:

default void complete(V value) {
  onNext(value);
  onCompleted();
}

WDYT?

@sergiitk
Copy link
Member

Thanks for the suggestion. We're going to discuss it with the team at our next API Stabilization meeting.

@ejona86
Copy link
Member

ejona86 commented Apr 23, 2024

API review notes (2024-04-09 (?) and 2024-04-18)

  • This could be done through a utility function. Doesn't seem people have made utility functions for themselves for this. If we just added it as a utility function, could be added to “StreamObservers” (and un-deprecate the class)
  • There's the option for Exception handling in the implementation - we don’t encourage try/catch around next in general, so not necessary for initial implementation
  • Shouldn’t name it “complete”; that's ambiguous - “onNextAndCompleted” seemed better
  • This is just added as syntactic sugar, users can use it if they want, but we don't need to encourage ti. We don't need to update the existing examples/docs to use it
  • Approved as experimental. @panchenko, feel free to send a PR to add StreamObserver.onNextAndCompleted()

@ejona86 ejona86 added this to the Unscheduled milestone Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants