Skip to content

Files

Latest commit

e4a4a91 · Jul 10, 2017

History

History
41 lines (29 loc) · 876 Bytes

README.md

File metadata and controls

41 lines (29 loc) · 876 Bytes

Promise

The promise library is an implementation of Promises/A+ specification in Java 8.

Getting Started

Create a pending promise

Promise<String> promise = new Promise<String>();

Create a pending promise with an executor

Promise<String> promise = new Promise<String>((resolve, reject) -> {
    ...
});

Resolve with value

Promise<String> promise = Promise.resolve("Promise/A+");

Reject with an exception

Promise<String> promise = Promise.reject(new RuntimeException("Oops!"));

Asynchronous HTTP

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());