Details
-
Sub-task
-
Status: Resolved
-
Major
-
Resolution: Done
-
None
Description
Describe
Using the original Java CompletableFuture to implement an asynchronous router is not conducive to the development of the open source community due to poor code readability and maintainability. Therefore, I have implemented a lightweight tool that encapsulates CompletableFuture.
By using this AsyncUtil, it is easy to write readable asynchronous code, which is easy for everyone to understand. I have provided an example of this tool class in UT, demonstrating how to change synchronous methods to asynchronous code.
Examples and tests
SyncClass provides some common synchronization methods
AsyncClass is the corresponding asynchronous implementation
Use TestAsyncUtil to simultaneously test the methods corresponding to SyncClass and AsyncClass, ensuring that both asynchronous and synchronous methods return the same results
NOTE: In HDFS-17545, I used this tool to implement RouterAsyncRpcClient which extends RouterRpcClient. You can also view RouterAsyncRpcClient to understand the use of this tool.
Attachments
Attachments
Issue Links
- links to