Skip to content

Commit 9c0549f

Browse files
committed
update doc with exception management
1 parent 0ae1302 commit 9c0549f

File tree

1 file changed

+67
-29
lines changed

1 file changed

+67
-29
lines changed

README.md

Lines changed: 67 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,18 @@
44

55
## Import
66

7+
In your build.gradle file, add the following :
8+
79
```
8-
TODO
10+
repositories {
11+
maven {
12+
url "https://dl.bintray.com/codlab/oss"
13+
}
14+
}
915
```
1016

17+
18+
1119
## Usage
1220

1321
The minimalistic Promise can be write such as :
@@ -24,34 +32,34 @@ The minimalistic Promise can be write such as :
2432
You can chain the promise with the following sample:
2533

2634
```java
27-
Promise<Boolean> promise = new Promise<>(new PromiseSolver<Boolean>() {
28-
@Override
29-
public void onCall(@NonNull Solver<Boolean> solver) {
30-
solver.resolve(false);
31-
}
32-
});
33-
34-
//chain it
35-
promise
36-
.then(new PromiseExec<Boolean, String>() {
37-
@Override
38-
public void onCall(@Nullable Boolean result, Solver<String> solver) {
39-
solver.resolve("previous result is := " + result);
40-
}
41-
})
42-
.then(new PromiseExec<String, Integer>() {
43-
@Override
44-
public void onCall(@Nullable String result, Solver<Integer> solver) {
45-
solver.resolve(result.length());
46-
}
47-
})
48-
.then(new PromiseExec<Integer, Object>() {
49-
@Override
50-
public void onCall(@Nullable Integer result, Solver<Object> solver) {
51-
//TODO something with the result which is the length of the appended false
52-
}
53-
})
54-
.execute();
35+
Promise<Boolean> promise = new Promise<>(new PromiseSolver<Boolean>() {
36+
@Override
37+
public void onCall(@NonNull Solver<Boolean> solver) {
38+
solver.resolve(false);
39+
}
40+
});
41+
42+
//chain it
43+
promise
44+
.then(new PromiseExec<Boolean, String>() {
45+
@Override
46+
public void onCall(@Nullable Boolean result, Solver<String> solver) {
47+
solver.resolve("previous result is := " + result);
48+
}
49+
})
50+
.then(new PromiseExec<String, Integer>() {
51+
@Override
52+
public void onCall(@Nullable String result, Solver<Integer> solver) {
53+
solver.resolve(result.length());
54+
}
55+
})
56+
.then(new PromiseExec<Integer, Object>() {
57+
@Override
58+
public void onCall(@Nullable Integer result, Solver<Object> solver) {
59+
//TODO something with the result which is the length of the appended false
60+
}
61+
})
62+
.execute();
5563
```
5664

5765
You can do whatever you want in the promise or the chained execution (Thread, Async post, Bugs, Save a cat)
@@ -71,7 +79,37 @@ Once one of those 2 calls are made, the promise will start resolving itself.
7179
Note that it is the best practice to manage the execution flow using `error(<ErrorPromise>)` to be sure
7280
to grab any issues the Promise resolution could throw !
7381

82+
Example :
83+
```
84+
new Promise<String>(new PromiseSolver<String>() {
85+
@Override
86+
public void onCall(@NonNull Solver<String> solver) {
87+
solver.resolve(null);
88+
}
89+
})
90+
.then(new PromiseExec<String, String>() {
91+
@Override
92+
public void onCall(@Nullable String result, @NonNull Solver<String> solver) {
93+
//exception thrown right here
94+
solver.resolve(result.toLowerCase());
95+
}
96+
})
97+
.then(new PromiseExec<String, Void>() {
98+
@Override
99+
public void onCall(@Nullable String result, @NonNull Solver<Void> solver) {
100+
System.out.println("you should not see this");
101+
}
102+
})
103+
.error(new ErrorPromise() {
104+
@Override
105+
public void onError(@NonNull Throwable error) {
106+
System.out.println("error catched");
107+
error.printStackTrace();
108+
}
109+
});
110+
```
74111

112+
Note : error() calls execute
75113
## Contributing
76114

77115
When contributing to this repository, please first discuss the change you wish to make via issue,

0 commit comments

Comments
 (0)