annotate Implab/SuccessPromise.cs @ 216:1e082fb67a46 v2

Fixed component container
author cin
date Tue, 25 Apr 2017 19:51:33 +0300
parents 4d9830a9bbb8
children cbe10ac0731e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
145
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
1 using System;
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
2
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
3 namespace Implab {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
4 public class SuccessPromise : IPromise {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
5 #region IPromise implementation
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
6
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
7 public IPromise On(Action success, Action<Exception> error, Action<Exception> cancel) {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
8 if (success != null) {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
9 try {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
10 success();
203
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents: 145
diff changeset
11 // Analysis disable once EmptyGeneralCatchClause
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents: 145
diff changeset
12 } catch {
145
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
13 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
14 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
15 return this;
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
16 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
17
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
18 public IPromise On(Action success, Action<Exception> error) {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
19 if (success != null) {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
20 try {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
21 success();
203
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents: 145
diff changeset
22 // Analysis disable once EmptyGeneralCatchClause
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents: 145
diff changeset
23 } catch {
145
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
24 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
25 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
26 return this;
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
27 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
28
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
29 public IPromise On(Action success) {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
30 if (success != null) {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
31 try {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
32 success();
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
33 // Analysis disable once EmptyGeneralCatchClause
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
34 } catch {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
35 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
36 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
37 return this;
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
38 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
39
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
40 public IPromise On(Action handler, PromiseEventType events) {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
41 if (handler != null && events.HasFlag(PromiseEventType.Success)) {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
42 try {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
43 handler();
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
44 // Analysis disable once EmptyGeneralCatchClause
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
45 } catch {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
46 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
47 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
48 return this;
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
49 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
50
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
51 public IPromise<T> Cast<T>() {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
52 throw new InvalidCastException();
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
53 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
54
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
55 public void Join() {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
56 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
57
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
58 public void Join(int timeout) {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
59 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
60
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
61 public Type PromiseType {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
62 get {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
63 return typeof(void);
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
64 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
65 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
66
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
67 public bool IsResolved {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
68 get {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
69 return true;
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
70 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
71 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
72
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
73 public bool IsCancelled {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
74 get {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
75 return false;
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
76 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
77 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
78
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
79 public Exception Error {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
80 get {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
81 return null;
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
82 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
83 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
84
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
85 #endregion
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
86
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
87 #region ICancellable implementation
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
88
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
89 public void Cancel() {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
90 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
91
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
92 public void Cancel(Exception reason) {
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
93 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
94
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
95 #endregion
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
96
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
97 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
98 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents:
diff changeset
99