Discuss how onComplete or onSuccess/onFailure can be used#5431
Discuss how onComplete or onSuccess/onFailure can be used#5431julianladisch wants to merge 1 commit intoeclipse-vertx:masterfrom
Conversation
0fb18e0 to
3aaa5d6
Compare
tsegismont
left a comment
There was a problem hiding this comment.
Thanks @julianladisch for bringing this up.
I have reservations about this one. Invoking onSuccess and onFailure at the same place implies creating two future listeners where a single one would do the trick.
If the goal is to avoid writing the if block, then there is an onComplete overload that takes two arguments, a success and a failure handler.
We should promote the usage of this method, imo.
That doesn't mean onSucess and onFailure don't have any use case (sometimes they're convenient, like when a method returning a future needs to perform a side action when the future is completed).
3aaa5d6 to
09fde45
Compare
09fde45 to
d5a5ca5
Compare
Simplify the code by replacing onComplete + if-ar.succeeded-else with either onComplete(res, e) or with other processing. Avoiding onComplete + if-ar.succeeded-else results in more concise and understandable code because it avoids the additional nesting of the if-else clause. Extend the `exampleFuture*` code to discuss all possibilities how onComplete and onSuccess/onFailure might be used. Remove unused exampleFuture2 from lines 173-186. A new exampleFuture2 is created in line 145.
d5a5ca5 to
e9fe56f
Compare
|
@tsegismont @vietj : Thank you for pointing out that invoking onSuccess and onFailure at the same place is slightly slower and takes slightly more memory. I've adjusted the changes accordingly. |
Motivation:
Simplify the code by replacing onComplete + if-ar.succeeded-else with
either onComplete(res, e) or with other processing.
Avoiding onComplete + if-ar.succeeded-else results in more concise and understandable
code because it avoids the additional nesting of the if-else clause.
Extend the
exampleFuture*code to discuss all possibilities how onComplete andonSuccess/onFailure might be used.
Conformance: