Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Vertx 3 support CompletableFuture?

I want to develop my application promise style using vertx and CompletableFuture fits really for this purpose but JVM uses fork/join on the background for CompletableFuture and this may break Vertx Thread Safety.

Do you have any idea or have used this feature on your project?

like image 724
firstthumb Avatar asked Oct 30 '25 00:10

firstthumb


2 Answers

There is also https://github.com/cescoffier/vertx-completable-future. From the README:

This project provides the Completable Future API but enforces the Vert.x threading model:

  • When using xAsync methods (without executor), the callbacks are called on the Vert.x context
  • When using non-async, it uses the caller thread. If it's a Vert.x thread the same thread is used. If not called from a Vert.x thread, it still uses the caller thread
  • When using xAsync methods with an Executor parameter, this executor is used to execute the callback (does not enforce the Vert.x thread system)

Haven't used yet, though.

like image 175
adave Avatar answered Nov 02 '25 13:11

adave


Yes it does, here is an example http://qrman.github.io/posts/2015/08/28/callback_hell_completablefuture_ftw/

But I think JavaRx is the better solution because its supported as first class citizen by vert.x http://vertx.io/docs/vertx-rx/java/

like image 36
haschibaschi Avatar answered Nov 02 '25 12:11

haschibaschi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!