145
|
1 using System;
|
|
2
|
|
3 namespace Implab {
|
|
4 public class SuccessPromise : IPromise {
|
|
5 #region IPromise implementation
|
|
6
|
|
7 public IPromise On(Action success, Action<Exception> error, Action<Exception> cancel) {
|
|
8 if (success != null) {
|
|
9 try {
|
|
10 success();
|
|
11 } catch(Exception err) {
|
|
12 if (error != null) {
|
|
13 try {
|
|
14 error(err);
|
|
15 // Analysis disable once EmptyGeneralCatchClause
|
|
16 } catch {
|
|
17 }
|
|
18 }
|
|
19 }
|
|
20 }
|
|
21 return this;
|
|
22 }
|
|
23
|
|
24 public IPromise On(Action success, Action<Exception> error) {
|
|
25 if (success != null) {
|
|
26 try {
|
|
27 success();
|
|
28 } catch(Exception err) {
|
|
29 if (error != null) {
|
|
30 try {
|
|
31 error(err);
|
|
32 // Analysis disable once EmptyGeneralCatchClause
|
|
33 } catch {
|
|
34 }
|
|
35 }
|
|
36 }
|
|
37 }
|
|
38 return this;
|
|
39 }
|
|
40
|
|
41 public IPromise On(Action success) {
|
|
42 if (success != null) {
|
|
43 try {
|
|
44 success();
|
|
45 // Analysis disable once EmptyGeneralCatchClause
|
|
46 } catch {
|
|
47 }
|
|
48 }
|
|
49 return this;
|
|
50 }
|
|
51
|
|
52 public IPromise On(Action handler, PromiseEventType events) {
|
|
53 if (handler != null && events.HasFlag(PromiseEventType.Success)) {
|
|
54 try {
|
|
55 handler();
|
|
56 // Analysis disable once EmptyGeneralCatchClause
|
|
57 } catch {
|
|
58 }
|
|
59 }
|
|
60 return this;
|
|
61 }
|
|
62
|
|
63 public IPromise<T> Cast<T>() {
|
|
64 throw new InvalidCastException();
|
|
65 }
|
|
66
|
|
67 public void Join() {
|
|
68 }
|
|
69
|
|
70 public void Join(int timeout) {
|
|
71 }
|
|
72
|
|
73 public Type PromiseType {
|
|
74 get {
|
|
75 return typeof(void);
|
|
76 }
|
|
77 }
|
|
78
|
|
79 public bool IsResolved {
|
|
80 get {
|
|
81 return true;
|
|
82 }
|
|
83 }
|
|
84
|
|
85 public bool IsCancelled {
|
|
86 get {
|
|
87 return false;
|
|
88 }
|
|
89 }
|
|
90
|
|
91 public Exception Error {
|
|
92 get {
|
|
93 return null;
|
|
94 }
|
|
95 }
|
|
96
|
|
97 #endregion
|
|
98
|
|
99 #region ICancellable implementation
|
|
100
|
|
101 public void Cancel() {
|
|
102 }
|
|
103
|
|
104 public void Cancel(Exception reason) {
|
|
105 }
|
|
106
|
|
107 #endregion
|
|
108
|
|
109 }
|
|
110 }
|
|
111
|