What is the cost (in terms of memory, performance, etc) of having threads block on the result of async operations (e.g. CompletableFuture
or RxJava
) versus propagating asynchronous promises to the caller of the method?
Why Am I asking this Question
3 months ago I drank the cool-aid and went all-asynchronous using CompletableFuture
. I've since come across the following complications:
- The code is much harder to read and maintain
- Debugging is harder:
- It is harder to loop or break out of loops
- Throwing and catching exceptions is more complicated:
- Documenting exceptions is a lot harder
- Deciding when to use sync vs async execution is not so clear cut
Without commenting on the severity of the above problems, let's just agree that async code is more complicated than it's sync counterpart.
I'm hoping that it is possible to limit the usage of async code to portions that benefit from it, while keeping the rest of the code synchronous.