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.
- related to
-
JAVA-3903 Replace internal use of callbacks with Reactor in mongodb-driver-core module
-
- Backlog
-