-
Notifications
You must be signed in to change notification settings - Fork 235
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
feat(s3stream): optimize the execution sequence to avoid deep depende… #1790
feat(s3stream): optimize the execution sequence to avoid deep depende… #1790
Conversation
How this PR solve you mentioned problems: 'execution order', 'code readability', 'debugging', and 'problem localization'? |
execution order: The callbacks will only execute in a FIFO (First In, First Out) order if the dependent CompletableFuture has already completed by the time new callbacks are attached. 'code readability', 'debugging', and 'problem localization' and I suggest choosing to create a new CompletableFuture object to expose to the outside between modules, while within the module, one can opt to rely on the object returned by whenComplete to ensure the orderliness of callback methods. Of course, these are just my personal understandings, and I welcome any corrections. Haha. |
In the original implementation, the execution order of the code in whenComplete remains FIFO. The current logic does not depend on the execution order of whenComplete and thenAccept appended after CompletableFuture. Return a CompletableFuture that appends whenComplete after it can execute the whenComplete logic N microseconds earlier. It‘s an acceptable change. However, I believe that adding extra CompleteFuture to break the chain does not bring more convenience for debugging or heap dump investigation. |
Thank you for your reply. You are right. The execution of dependencies for the CompletableFuture object returned by whenComplete is FIFO |
Background: Due to the fact that the callback order of CompletableFuture follows a LIFO (Last In First Out) pattern, the current implementation cannot guarantee the execution order. Furthermore, exposing CompletableFuture to external callers of S3Stream leads to deep dependencies, which subsequently affects code readability, debugging, and problem localization.