Skip to content

More helper methods in StatementResultCursor #410

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

Merged
merged 5 commits into from
Sep 29, 2017

Conversation

lutovich
Copy link
Contributor

This PR adds following methods to StatementResultCursor:

  • CompletionStage<Record> singleAsync() to safely retrieve single record from the cursor and assert that cursor contains exactly one record
  • CompletionStage<List<T>> listAsync(Function<Record, T>) to transform all incoming records and store them in list
  • CompletionStage<ResultSummary> consumeAsync() to drop/skip all incoming records and get result summary

They are added for convenience and to be consistent with existing blocking API in StatementResult.

Also #forEachAsync(Consumer<Record>) now returns future of ResultSummary.

Which returns future of a record if result contains a single record.
Otherwise it returns a failed future. This method is convenient and
safe shortcut for consuming a single-record result.
`StatementResultCursor#forEachAsync()` will now return future of
`ResultSummary` instead of future of void. This simplifies the
API a bit an makes it more convenient to use summary after
forEach is completed.
New method allows application of a transformation function to each
record. Returned list will contain transformed values. This allows
writing a bit more concise code when records need to be converted
to some other objects. Returned future will be failed if given
function ever throws.

Also improved error handling in `#forEachAsync(Consumer<Record>)`.
Which allows skip/drop all incoming records and returns future
of `ResultSummary`.
Otherwise TCK tests fail.
Copy link
Contributor

@ali-ince ali-ince left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@lutovich lutovich merged commit 24e87be into neo4j:1.5 Sep 29, 2017
@lutovich lutovich deleted the 1.5-more-async-cursor-methods branch September 29, 2017 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants