=doc #20133 Fixed doc about futures
This commit is contained in:
parent
aff158cb98
commit
2984022ccc
2 changed files with 2 additions and 84 deletions
|
|
@ -157,56 +157,6 @@ public class FutureDocTest extends AbstractJavaTest {
|
|||
assertEquals(10, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void useMap2() throws Exception {
|
||||
//#map2
|
||||
final ExecutionContext ec = system.dispatcher();
|
||||
|
||||
Future<String> f1 = future(new Callable<String>() {
|
||||
public String call() throws Exception {
|
||||
Thread.sleep(100);
|
||||
return "Hello" + "World";
|
||||
}
|
||||
}, ec);
|
||||
|
||||
Future<Integer> f2 = f1.map(new Mapper<String, Integer>() {
|
||||
public Integer apply(String s) {
|
||||
return s.length();
|
||||
}
|
||||
}, ec);
|
||||
|
||||
f2.onSuccess(new PrintResult<Integer>(), system.dispatcher());
|
||||
//#map2
|
||||
int result = Await.result(f2, Duration.create(5, SECONDS));
|
||||
assertEquals(10, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void useMap3() throws Exception {
|
||||
//#map3
|
||||
final ExecutionContext ec = system.dispatcher();
|
||||
|
||||
Future<String> f1 = future(new Callable<String>() {
|
||||
public String call() {
|
||||
return "Hello" + "World";
|
||||
}
|
||||
}, ec);
|
||||
|
||||
// Thread.sleep is only here to prove a point
|
||||
Thread.sleep(100); // Do not use this in your code
|
||||
|
||||
Future<Integer> f2 = f1.map(new Mapper<String, Integer>() {
|
||||
public Integer apply(String s) {
|
||||
return s.length();
|
||||
}
|
||||
}, ec);
|
||||
|
||||
f2.onSuccess(new PrintResult<Integer>(), system.dispatcher());
|
||||
//#map3
|
||||
int result = Await.result(f2, Duration.create(5, SECONDS));
|
||||
assertEquals(10, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void useFlatMap() throws Exception {
|
||||
//#flat-map
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue