Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

first() and all(): Add syntactic sugar to treat ServerStreamingCallables like UnaryCallables #444

Merged
merged 6 commits into from
Dec 20, 2017

Conversation

igorbernstein2
Copy link
Contributor

This PR adds first() and all() callables on top of ServerStreamingCallables. This allows for simple interaction with short server streams. Example usage:

Row row = client.readRowsCallable().first().call(request)
ApiFuture<List<Row>> rows = client.readRowsCallable().all().futureCall(request)

@codecov-io
Copy link

codecov-io commented Dec 13, 2017

Codecov Report

Merging #444 into master will increase coverage by 0.45%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #444      +/-   ##
============================================
+ Coverage     71.48%   71.94%   +0.45%     
- Complexity      728      746      +18     
============================================
  Files           150      154       +4     
  Lines          3276     3329      +53     
  Branches        256      256              
============================================
+ Hits           2342     2395      +53     
  Misses          837      837              
  Partials         97       97
Impacted Files Coverage Δ Complexity Δ
...om/google/api/gax/rpc/ServerStreamingCallable.java 50% <100%> (+9.25%) 7 <3> (+2) ⬆️
...ogle/api/gax/rpc/FirstElementResponseObserver.java 100% <100%> (ø) 6 <6> (?)
...a/com/google/api/gax/rpc/FirstElementCallable.java 100% <100%> (ø) 2 <2> (?)
.../java/com/google/api/gax/rpc/SpoolingCallable.java 100% <100%> (ø) 2 <2> (?)
...m/google/api/gax/rpc/SpoolingResponseObserver.java 100% <100%> (ø) 6 <6> (?)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update deb1d7a...cfa1ef7. Read the comment docs.

import java.util.List;

/**
* A {@link ResponseObserver} that buffers the results from a {@link ServerStreamingCallable} in a

This comment was marked as spam.

This comment was marked as spam.


/**
* Construct a {@link UnaryCallable} that will yield the first item in the stream and cancel it.
* If the stream was empty, the item will be null.

This comment was marked as spam.

This comment was marked as spam.


/**
* Construct a {@link UnaryCallable} that will buffer the entire stream into memory before
* completing. If the stream was empty, then the list will be empty.

This comment was marked as spam.

This comment was marked as spam.

*
* <pre>{@code
* StreamingCallable<String> streamingCallable = // ..
* List<String></String> theResult = streamingCallable.all().call(request);

This comment was marked as spam.

This comment was marked as spam.


/**
* Simple implementation of a future to prematurely interrupt the RPC before the first element is
* received.

This comment was marked as spam.

This comment was marked as spam.

@igorbernstein2
Copy link
Contributor Author

rebased


@Override
public void onError(Throwable t) {
future.setException(t);

This comment was marked as spam.

This comment was marked as spam.

@garrettjonesgoogle
Copy link
Member

LGTM

@garrettjonesgoogle garrettjonesgoogle merged commit 532aae0 into googleapis:master Dec 20, 2017
@igorbernstein2 igorbernstein2 deleted the ssc-5-first-last branch January 10, 2018 05:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants