4
4
5
5
## Import
6
6
7
+ In your build.gradle file, add the following :
8
+
7
9
```
8
- TODO
10
+ repositories {
11
+ maven {
12
+ url "https://dl.bintray.com/codlab/oss"
13
+ }
14
+ }
9
15
```
10
16
17
+
18
+
11
19
## Usage
12
20
13
21
The minimalistic Promise can be write such as :
@@ -24,34 +32,34 @@ The minimalistic Promise can be write such as :
24
32
You can chain the promise with the following sample:
25
33
26
34
``` 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();
55
63
```
56
64
57
65
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.
71
79
Note that it is the best practice to manage the execution flow using ` error(<ErrorPromise>) ` to be sure
72
80
to grab any issues the Promise resolution could throw !
73
81
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
+ ```
74
111
112
+ Note : error() calls execute
75
113
## Contributing
76
114
77
115
When contributing to this repository, please first discuss the change you wish to make via issue,
0 commit comments