1
1
package eu .codlab .simplepromise ;
2
2
3
3
import android .os .Handler ;
4
+ import android .os .Looper ;
4
5
import android .support .annotation .NonNull ;
6
+ import android .support .annotation .Nullable ;
5
7
6
8
import java .util .List ;
7
9
8
10
import eu .codlab .simplepromise .solve .ErrorPromise ;
9
11
import eu .codlab .simplepromise .solve .PromiseExec ;
10
12
import eu .codlab .simplepromise .solve .PromiseSolver ;
13
+ import eu .codlab .simplepromise .solve .Solver ;
11
14
12
15
public class Promise <TYPE > extends AbstractPromise <TYPE > {
13
16
@@ -16,7 +19,7 @@ public static <T> Promise<List<T>> all(AbstractPromise<T>...promises) {
16
19
}
17
20
18
21
@ NonNull
19
- private static Handler sHandler = new Handler ();
22
+ private static Handler sHandler = new Handler (Looper . getMainLooper () );
20
23
21
24
public static void setHandler (@ NonNull Handler handler ) {
22
25
sHandler = handler ;
@@ -45,6 +48,16 @@ public <TYPE_RESULT> PromiseInOut<TYPE, TYPE_RESULT> then(PromiseExec<TYPE, TYPE
45
48
return then (new PromiseInOut <>(to_resolve ));
46
49
}
47
50
51
+ public <TYPE_RESULT > PromiseInOut <TYPE , TYPE_RESULT > then (final TYPE_RESULT resolved ) {
52
+ return then (new PromiseExec <TYPE , TYPE_RESULT >() {
53
+ @ Override
54
+ public void onCall (@ Nullable TYPE result , @ NonNull Solver <TYPE_RESULT > solver ) {
55
+ solver .resolve (resolved );
56
+ }
57
+ });
58
+ }
59
+
60
+
48
61
public <TYPE_RESULT > void error (ErrorPromise to_error ) {
49
62
PromiseInOut <TYPE , TYPE_RESULT > promise_inout = new PromiseInOut <>(to_error );
50
63
promise_inout .setParent (mPromiseInOut );
0 commit comments