[JAVA-5082] Internal framework to increase velocity of reactive streams implementation Created: 17/Jul/23  Updated: 30/Nov/23

Status: In Code Review
Project: Java Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Unknown
Reporter: Maxim Katcharov Assignee: Maxim Katcharov
Resolution: Unresolved Votes: 0
Labels: tech-debt
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to JAVA-3903 Replace internal use of callbacks wit... Backlog
Quarter: FY24Q4
Documentation Changes Summary:

1. What would you like to communicate to the user about this feature?
2. Would you like the user to see examples of the syntax and/or executable code and its output?
3. Which versions of the driver/connector does this apply to?


 Description   

Recent work with async code added a few async helper methods, which developed into a candidate API for writing async code in the driver. The team should evaluate whether this API might be used for writing async code.

If it fits our needs, this API might be used to simplify new async code. It might remove the need to switch to Project Reactor for our async code. We may need a document or examples that would help us to evaluate and determine how to proceed.

For example, much of our async code looks like this:

try {
    plain(11)
    async(1, c1 -> {
        try {
            plain(22);
            async(2, callback)
        } catch (...) { ...callback... }
    })
} catch (...) { ...callback... }

There is substantial boilerplate, especially in larger examples. The nesting is also difficult to read. It corresponds to the following sync code, where "plain" is a plain sync method, and "sync" is a sync method that must be converted to an async method when writing the above corresponding async code.

plain(11);
sync(1);
plain(22);
sync(2);

The revised API proposes the following mechanism:

beginAsync().thenRun(c -> {
    plain(11);
    async(1, c);
}).thenRun(c -> {
    plain(22);
    async(2, c);
}).finish(callback);

Other examples can be found here.


Generated at Thu Feb 08 09:03:41 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.