Hi,
I would like to know if exist any example using Future objects provided by vavr.
I read the documentation, but I have the feeling that the chapter is a bit short.
http://www.vavr.io/vavr-docs/#_future
Juan Antonio
@jabrena Thanks for asking!
Right, the docs can be improved. We will do that for the 1.0.0 release.
If you know Scala, I would suggest to read the Scala docs on Future/Promise. Vavr works basically the same.
You could take a look at our unit tests FutureTest and PromiseTest.
In fact, Future is a very elegant way to handle async computations in Java. They are composable, e.g.
Future.of(() -> /*this takes veeeery looong*/) // but this call does not block
.map(result -> ...) // the function parameter is called as soon as the result is available
.onComplete(result -> ...); // don't use get(), it blocks
Future<Seq<T>> futures = Future.sequence(future1, future2, ...);
// or
Future<Seq<User>> users = List.of(1, 2, 3).map(userId -> Future.of(() -> db.loadUser(userId)));
Documentation will be part of Vavr 1.0.0. I will close this issue. Thx for asking!
Most helpful comment
Documentation will be part of Vavr 1.0.0. I will close this issue. Thx for asking!