@Retention(value=RUNTIME) @Target(value=METHOD) public @interface Async
import com.ea.orbit.async.Async;
import static com.ea.orbit.async.Await.await;
...
Async
CompletableFuture getPageLengthAsync()
{
CompletableFuture pageFuture = getPageAsync("http://example.com");
String page = await(pageFuture);
return CompletableFuture.completedFuture(page.length);
}
Or using orbit Task:
Async
Task CompletableFuture getPageLengthAsync()
{
Task pageFuture = getPageAsync("http://example.com");
String page = await(pageFuture);
return Task.fromValue(page.length);
}
Caveat: The following code must be called before the program execution:
static { Await.init() }
Otherwise, the first method to call await() might be blocking,
and a warning message will be printed to the console.
Subsequent async methods will work as expected.Copyright © 2015 Electronic Arts Inc. All rights reserved.