Skip to content

sdklite/promise

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Promises/A+ implementation in Java 8

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages