-
-
Notifications
You must be signed in to change notification settings - Fork 57
/
VavrFuture.java
32 lines (25 loc) · 979 Bytes
/
VavrFuture.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package vavr;
import io.vavr.concurrent.Future;
import org.junit.Test;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class VavrFuture {
@Test
public void simpleFuture() {
Future<Void> future = Future.run(() -> System.out.println("Hello world in " + Thread.currentThread().getName()));
future.await();
}
@Test
public void simpleFutureOnExecutor() {
ExecutorService executor = Executors.newFixedThreadPool(100);
Future<Void> future = Future.run(executor, () -> System.out.println("Hello world in " + Thread.currentThread().getName()));
future.await();
}
@Test
public void flatMapFuture() {
Future<String> future = Future.of(() -> "Hello world in ")
.flatMap(sentence -> Future.of(() -> sentence + Thread.currentThread().getName()))
.map(String::toUpperCase);
System.out.println(future.await().get());
}
}