The promise library is an implementation of Promises/A+ specification in Java 8.
Promise<String> promise = new Promise<String>();
Promise<String> promise = new Promise<String>((resolve, reject) -> {
...
});
Promise<String> promise = Promise.resolve("Promise/A+");
Promise<String> promise = Promise.reject(new RuntimeException("Oops!"));
Promise.resolve('https://api.github.com/').then(url -> {
try (final InputStreamReader reader = new InputStreamReader(new URL(url).openStream())) {
return IOUtils.readFully(reader);
}
}).then(System.out::println, e -> e.printStackTrace());