A promise represents a future value (usually of an asynchronous operation).
This is a simple implementation of Promises/A+ in Java, based on RxJava's architecture.
Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
compile 'com.github.SMontiel:Promise:0.2.1'
}
Promise<String> p = Promise.resolve("Hello world");
p.then(new Consumer<String>() {
@Override
public void accept(String s) {
System.out.println(s);
}
}).then(new Function<String, Integer>() {
@Override
public Integer apply(String s) {
return s.length();
}
}).then(new Consumer<Integer>() {
@Override
public void accept(Integer integer) {
System.out.println("Length of " + integer);
}
}).done();
Output:
Hello world!
Length of 12
Building Promise
with Gradle is fairly straight forward:
git clone https://github.com/SMontiel/Promise.git
cd Promise
./gradlew build
For bugs, questions and discussions please use the Github Issues.