comparison Implab/AbstractPromise.cs @ 145:706fccb85524 v2

RC: cancellation support for promises + tests
author cin
date Sun, 08 Mar 2015 02:52:27 +0300
parents 8c0b95069066
children 97fbbf816844
comparison
equal deleted inserted replaced
144:8c0b95069066 145:706fccb85524
16 m_mask = PromiseEventType.Success; 16 m_mask = PromiseEventType.Success;
17 } 17 }
18 18
19 public HandlerDescriptor(Action handler, PromiseEventType mask) { 19 public HandlerDescriptor(Action handler, PromiseEventType mask) {
20 m_handler = handler; 20 m_handler = handler;
21 m_error = null;
22 m_cancel = null;
21 m_mask = mask; 23 m_mask = mask;
22 } 24 }
23 25
24 public void SignalSuccess() { 26 public void SignalSuccess() {
25 if (m_mask & PromiseEventType.Success && m_handler != null) { 27 if ((m_mask & PromiseEventType.Success) != 0 && m_handler != null) {
26 try { 28 try {
27 m_handler(); 29 m_handler();
28 } catch (Exception err) { 30 } catch (Exception err) {
29 // avoid calling handler twice in case of error 31 // avoid calling handler twice in case of error
30 if (m_error != null) 32 if (m_error != null)
38 try { 40 try {
39 m_error(err); 41 m_error(err);
40 // Analysis disable once EmptyGeneralCatchClause 42 // Analysis disable once EmptyGeneralCatchClause
41 } catch { 43 } catch {
42 } 44 }
43 } else if (m_mask & PromiseEventType.Error && m_handler != null) { 45 } else if ((m_mask & PromiseEventType.Error ) != 0 && m_handler != null) {
44 try { 46 try {
45 m_handler(); 47 m_handler();
46 // Analysis disable once EmptyGeneralCatchClause 48 // Analysis disable once EmptyGeneralCatchClause
47 } catch { 49 } catch {
48 } 50 }
54 try { 56 try {
55 m_cancel(reason); 57 m_cancel(reason);
56 } catch (Exception err) { 58 } catch (Exception err) {
57 SignalError(err); 59 SignalError(err);
58 } 60 }
59 } else if (m_mask & PromiseEventType.Cancelled && m_handler != null) { 61 } else if ( (m_mask & PromiseEventType.Cancelled) != 0 && m_handler != null) {
60 try { 62 try {
61 m_handler(); 63 m_handler();
62 // Analysis disable once EmptyGeneralCatchClause 64 // Analysis disable once EmptyGeneralCatchClause
63 } catch { 65 } catch {
64 } 66 }
82 } 84 }
83 85
84 protected override Signal GetResolveSignal() { 86 protected override Signal GetResolveSignal() {
85 var signal = new Signal(); 87 var signal = new Signal();
86 On(signal.Set, PromiseEventType.All); 88 On(signal.Set, PromiseEventType.All);
89 return signal;
87 } 90 }
88 91
89 #endregion 92 #endregion
90
91 93
92 public Type PromiseType { 94 public Type PromiseType {
93 get { 95 get {
94 return typeof(void); 96 return typeof(void);
95 } 97 }