annotate Implab/PromiseExtensions.cs @ 260:547a2fc0d93e v3 v3.0.6

minor fixes
author cin
date Fri, 13 Apr 2018 19:14:59 +0300
parents 7d52dc684bbd
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
72
d67b95eddaf4 promises refactoring
cin
parents:
diff changeset
1 using System.Threading;
75
4439140706d0 major refactoring, added tasks support
cin
parents: 72
diff changeset
2 using System;
109
1b7ebcc52e5a minor fixes
cin
parents: 104
diff changeset
3 using Implab.Diagnostics;
119
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents: 110
diff changeset
4 using System.Collections.Generic;
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
5 using System.Linq;
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
6
72
d67b95eddaf4 promises refactoring
cin
parents:
diff changeset
7 namespace Implab {
d67b95eddaf4 promises refactoring
cin
parents:
diff changeset
8 public static class PromiseExtensions {
d67b95eddaf4 promises refactoring
cin
parents:
diff changeset
9
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
10 public static IPromise Then(this IPromise that, Action fulfilled, Action<Exception> rejected) {
249
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
11 var reaction = PromiseActionReaction.Create(fulfilled, rejected, Promise.DefaultDispatcher);
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
12 that.Then(reaction);
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
13 return reaction.Promise;
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
14 }
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
15
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
16 public static IPromise Then(this IPromise that, Action fulfilled) {
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
17 var reaction = PromiseActionReaction.Create(fulfilled, null, Promise.DefaultDispatcher);
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
18 that.Then(reaction);
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
19 return reaction.Promise;
101
279e226dffdd code cleanup
cin
parents: 76
diff changeset
20 }
279e226dffdd code cleanup
cin
parents: 76
diff changeset
21
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
22 public static IPromise Then(this IPromise that, Action fulfilled, Func<Exception, IPromise> rejected) {
249
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
23 var reaction = PromiseActionReaction.Create(fulfilled, rejected, Promise.DefaultDispatcher);
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
24 that.Then(reaction);
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
25 return reaction.Promise;
207
558f34b2fb50 added Safe.DispatchEvent() a legacy equivalent for '?.Invoke()'
cin
parents: 205
diff changeset
26 }
558f34b2fb50 added Safe.DispatchEvent() a legacy equivalent for '?.Invoke()'
cin
parents: 205
diff changeset
27
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
28 public static IPromise Then(this IPromise that, Func<IPromise> fulfilled, Action<Exception> rejected) {
249
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
29 var reaction = PromiseActionReaction.Create(fulfilled, rejected, Promise.DefaultDispatcher);
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
30 that.Then(reaction);
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
31 return reaction.Promise;
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
32 }
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
33
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
34 public static IPromise Then(this IPromise that, Func<IPromise> fulfilled) {
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
35 var reaction = PromiseActionReaction.Create(fulfilled, null, Promise.DefaultDispatcher);
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
36 that.Then(reaction);
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
37 return reaction.Promise;
75
4439140706d0 major refactoring, added tasks support
cin
parents: 72
diff changeset
38 }
110
1a8426e6e895 added promise timeout helper
cin
parents: 109
diff changeset
39
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
40 public static IPromise Then(this IPromise that, Func<IPromise> fulfilled, Func<Exception, IPromise> rejected) {
249
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
41 var reaction = PromiseActionReaction.Create(fulfilled, rejected, Promise.DefaultDispatcher);
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
42 that.Then(reaction);
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
43 return reaction.Promise;
110
1a8426e6e895 added promise timeout helper
cin
parents: 109
diff changeset
44 }
119
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents: 110
diff changeset
45
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
46 public static IPromise Then<T>(this IPromise<T> that, Action<T> fulfilled, Action<Exception> rejected) {
249
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
47 var reaction = PromiseActionReaction<T>.Create(fulfilled, rejected, Promise.DefaultDispatcher);
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
48 that.Then(reaction);
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
49 return reaction.Promise;
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
50 }
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
51
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
52 public static IPromise Then<T>(this IPromise<T> that, Action<T> fulfilled) {
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
53 var reaction = PromiseActionReaction<T>.Create(fulfilled, null, Promise.DefaultDispatcher);
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
54 that.Then(reaction);
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
55 return reaction.Promise;
205
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 185
diff changeset
56 }
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 185
diff changeset
57
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
58 public static IPromise Then<T>(this IPromise<T> that, Action<T> fulfilled, Func<Exception, IPromise> rejected) {
249
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
59 var reaction = PromiseActionReaction<T>.Create(fulfilled, rejected, Promise.DefaultDispatcher);
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
60 that.Then(reaction);
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
61 return reaction.Promise;
208
7d07503621fe RunnableComponent.Dispose(bool,Exception) changed to standart Dispose(bool)
cin
parents: 207
diff changeset
62 }
7d07503621fe RunnableComponent.Dispose(bool,Exception) changed to standart Dispose(bool)
cin
parents: 207
diff changeset
63
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
64 public static IPromise Then<T>(this IPromise<T> that, Func<T, IPromise> fulfilled, Action<Exception> rejected) {
249
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
65 var reaction = PromiseActionReaction<T>.Create(fulfilled, rejected, Promise.DefaultDispatcher);
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
66 that.Then(reaction);
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
67 return reaction.Promise;
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
68 }
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
69
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
70 public static IPromise Then<T>(this IPromise<T> that, Func<T, IPromise> fulfilled) {
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
71 var reaction = PromiseActionReaction<T>.Create(fulfilled, null, Promise.DefaultDispatcher);
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
72 that.Then(reaction);
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
73 return reaction.Promise;
124
a336cb13c6a9 major update, added Drain mathod to AsyncQueue class
cin
parents: 119
diff changeset
74 }
145
706fccb85524 RC: cancellation support for promises + tests
cin
parents: 138
diff changeset
75
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
76 public static IPromise Then<T>(this IPromise<T> that, Func<T, IPromise> fulfilled, Func<Exception, IPromise> rejected) {
249
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
77 var reaction = PromiseActionReaction<T>.Create(fulfilled, rejected, Promise.DefaultDispatcher);
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
78 that.Then(reaction);
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
79 return reaction.Promise;
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
80 }
145
706fccb85524 RC: cancellation support for promises + tests
cin
parents: 138
diff changeset
81
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
82 public static IPromise<Tout> Then<Tout>(this IPromise that, Func<Tout> fulfilled, Func<Exception, Tout> rejected) {
249
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
83 var reaction = PromiseFuncReaction<Tout>.Create(fulfilled, rejected, Promise.DefaultDispatcher);
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
84 that.Then(reaction);
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
85 return reaction.Promise;
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
86 }
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
87
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
88 public static IPromise<Tout> Then<Tout>(this IPromise that, Func<Tout> fulfilled) {
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
89 var reaction = PromiseFuncReaction<Tout>.Create(fulfilled, (Func<Exception, Tout>)null, Promise.DefaultDispatcher);
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
90 that.Then(reaction);
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
91 return reaction.Promise;
145
706fccb85524 RC: cancellation support for promises + tests
cin
parents: 138
diff changeset
92 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents: 138
diff changeset
93
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
94 public static IPromise<Tout> Then<Tout>(this IPromise that, Func<Tout> fulfilled, Func<Exception, IPromise<Tout>> rejected) {
249
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
95 var reaction = PromiseFuncReaction<Tout>.Create(fulfilled, rejected, Promise.DefaultDispatcher);
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
96 that.Then(reaction);
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
97 return reaction.Promise;
145
706fccb85524 RC: cancellation support for promises + tests
cin
parents: 138
diff changeset
98 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents: 138
diff changeset
99
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
100 public static IPromise<Tout> Then<Tout>(this IPromise that, Func<IPromise<Tout>> fulfilled, Func<Exception, Tout> rejected) {
249
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
101 var reaction = PromiseFuncReaction<Tout>.Create(fulfilled, rejected, Promise.DefaultDispatcher);
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
102 that.Then(reaction);
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
103 return reaction.Promise;
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
104 }
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
105
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
106 public static IPromise<Tout> Then<Tout>(this IPromise that, Func<IPromise<Tout>> fulfilled) {
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
107 var reaction = PromiseFuncReaction<Tout>.Create(fulfilled, (Func<Exception, Tout>)null, Promise.DefaultDispatcher);
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
108 that.Then(reaction);
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
109 return reaction.Promise;
207
558f34b2fb50 added Safe.DispatchEvent() a legacy equivalent for '?.Invoke()'
cin
parents: 205
diff changeset
110 }
558f34b2fb50 added Safe.DispatchEvent() a legacy equivalent for '?.Invoke()'
cin
parents: 205
diff changeset
111
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
112 public static IPromise<Tout> Then<Tout>(this IPromise that, Func<IPromise<Tout>> fulfilled, Func<Exception, IPromise<Tout>> rejected) {
249
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
113 var reaction = PromiseFuncReaction<Tout>.Create(fulfilled, rejected, Promise.DefaultDispatcher);
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
114 that.Then(reaction);
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
115 return reaction.Promise;
145
706fccb85524 RC: cancellation support for promises + tests
cin
parents: 138
diff changeset
116 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents: 138
diff changeset
117
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
118 public static IPromise<Tout> Then<Tin, Tout>(this IPromise<Tin> that, Func<Tin, Tout> fulfilled, Func<Exception, Tout> rejected) {
249
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
119 var reaction = PromiseFuncReaction<Tin, Tout>.Create(fulfilled, rejected, Promise.DefaultDispatcher);
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
120 that.Then(reaction);
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
121 return reaction.Promise;
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
122 }
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
123
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
124 public static IPromise<Tout> Then<Tin, Tout>(this IPromise<Tin> that, Func<Tin, Tout> fulfilled) {
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
125 var reaction = PromiseFuncReaction<Tin, Tout>.Create(fulfilled, (Func<Exception, Tout>)null, Promise.DefaultDispatcher);
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
126 that.Then(reaction);
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
127 return reaction.Promise;
207
558f34b2fb50 added Safe.DispatchEvent() a legacy equivalent for '?.Invoke()'
cin
parents: 205
diff changeset
128 }
558f34b2fb50 added Safe.DispatchEvent() a legacy equivalent for '?.Invoke()'
cin
parents: 205
diff changeset
129
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
130 public static IPromise<Tout> Then<Tin, Tout>(this IPromise<Tin> that, Func<Tin, Tout> fulfilled, Func<Exception, IPromise<Tout>> rejected) {
249
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
131 var reaction = PromiseFuncReaction<Tin, Tout>.Create(fulfilled, rejected, Promise.DefaultDispatcher);
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
132 that.Then(reaction);
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
133 return reaction.Promise;
207
558f34b2fb50 added Safe.DispatchEvent() a legacy equivalent for '?.Invoke()'
cin
parents: 205
diff changeset
134 }
558f34b2fb50 added Safe.DispatchEvent() a legacy equivalent for '?.Invoke()'
cin
parents: 205
diff changeset
135
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
136 public static IPromise<Tout> Then<Tin, Tout>(this IPromise<Tin> that, Func<Tin, IPromise<Tout>> fulfilled, Func<Exception, Tout> rejected) {
249
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
137 var reaction = PromiseFuncReaction<Tin, Tout>.Create(fulfilled, rejected, Promise.DefaultDispatcher);
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
138 that.Then(reaction);
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
139 return reaction.Promise;
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
140 }
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
141
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
142 public static IPromise<Tout> Then<Tin, Tout>(this IPromise<Tin> that, Func<Tin, IPromise<Tout>> fulfilled) {
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
143 var reaction = PromiseFuncReaction<Tin, Tout>.Create(fulfilled, (Func<Exception, Tout>)null, Promise.DefaultDispatcher);
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
144 that.Then(reaction);
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
145 return reaction.Promise;
207
558f34b2fb50 added Safe.DispatchEvent() a legacy equivalent for '?.Invoke()'
cin
parents: 205
diff changeset
146 }
558f34b2fb50 added Safe.DispatchEvent() a legacy equivalent for '?.Invoke()'
cin
parents: 205
diff changeset
147
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
148 public static IPromise<Tout> Then<Tin, Tout>(this IPromise<Tin> that, Func<Tin, IPromise<Tout>> fulfilled, Func<Exception, IPromise<Tout>> rejected) {
249
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
149 var reaction = PromiseFuncReaction<Tin, Tout>.Create(fulfilled, rejected, Promise.DefaultDispatcher);
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
150 that.Then(reaction);
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
151 return reaction.Promise;
145
706fccb85524 RC: cancellation support for promises + tests
cin
parents: 138
diff changeset
152 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents: 138
diff changeset
153
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
154 public static IPromise Catch(this IPromise that, Action<Exception> rejected) {
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
155 return Then(that, null, rejected);
145
706fccb85524 RC: cancellation support for promises + tests
cin
parents: 138
diff changeset
156 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents: 138
diff changeset
157
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
158 public static IPromise Catch(this IPromise that, Func<Exception, IPromise> rejected) {
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
159 return Then(that, null, rejected);
145
706fccb85524 RC: cancellation support for promises + tests
cin
parents: 138
diff changeset
160 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents: 138
diff changeset
161
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
162 public static IPromise<Tout> Catch<Tout>(this IPromise that, Func<Exception, Tout> rejected) {
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
163 return Then(that, (Func<Tout>)null, rejected);
145
706fccb85524 RC: cancellation support for promises + tests
cin
parents: 138
diff changeset
164 }
706fccb85524 RC: cancellation support for promises + tests
cin
parents: 138
diff changeset
165
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
166 public static IPromise<Tout> Catch<Tout>(this IPromise that, Func<Exception, IPromise<Tout>> rejected) {
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
167 return Then(that, (Func<Tout>)null, rejected);
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
168 }
75
4439140706d0 major refactoring, added tasks support
cin
parents: 72
diff changeset
169
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
170 public static IPromise<Tout> Catch<Tin, Tout>(this IPromise<Tin> that, Func<Exception, Tout> rejected) {
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
171 return Then(that, (Func<Tin, Tout>)null, rejected);
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
172 }
208
7d07503621fe RunnableComponent.Dispose(bool,Exception) changed to standart Dispose(bool)
cin
parents: 207
diff changeset
173
248
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
174 public static IPromise<Tout> Catch<Tin, Tout>(this IPromise<Tin> that, Func<Exception, IPromise<Tout>> rejected) {
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
175 return Then(that, (Func<Tin, Tout>)null, rejected);
5cb4826c2c2a Added awaiters to promises
cin
parents: 209
diff changeset
176 }
249
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
177
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
178 public static IPromise Finally(this IPromise that, Action final) {
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
179 return Then(that, final, e => {
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
180 final();
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
181 throw e.Rethrow();
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
182 });
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
183 }
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
184
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
185 public static IPromise Finally(this IPromise that, Func<IPromise> final) {
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
186 return Then(that, final, e => {
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
187 final();
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
188 throw e.Rethrow();
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
189 });
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
190 }
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
191
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
192 public static IPromise<T> Finally<T>(this IPromise<T> that, Action final) {
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
193 return Then<T, T>(that, x => {
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
194 final();
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
195 return x;
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
196 }, new Func<Exception, T>(e => {
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
197 final();
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
198 throw e.Rethrow();
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
199 }));
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
200 }
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
201
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
202 public static IPromise<T> Finally<T>(this IPromise<T> that, Func<IPromise> final) {
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
203 return Then<T, T>(that, x => {
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
204 return final()
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
205 .Then(() => x);
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
206 }, new Func<Exception, IPromise<T>>(e => {
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
207 return final()
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
208 .Then(new Func<T>(() => {
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
209 throw e.Rethrow();
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
210 }));
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
211 }));
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
212 }
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
213
259
7d52dc684bbd PollingComponent: implemented correct stopping
cin
parents: 249
diff changeset
214 public static PromiseAwaiter GetAwaiter(this IPromise that) {
7d52dc684bbd PollingComponent: implemented correct stopping
cin
parents: 249
diff changeset
215 Safe.ArgumentNotNull(that, nameof(that));
7d52dc684bbd PollingComponent: implemented correct stopping
cin
parents: 249
diff changeset
216 return new PromiseAwaiter(that);
7d52dc684bbd PollingComponent: implemented correct stopping
cin
parents: 249
diff changeset
217 }
7d52dc684bbd PollingComponent: implemented correct stopping
cin
parents: 249
diff changeset
218
7d52dc684bbd PollingComponent: implemented correct stopping
cin
parents: 249
diff changeset
219 public static PromiseAwaiter<T> GetAwaiter<T>(this IPromise<T> that) {
7d52dc684bbd PollingComponent: implemented correct stopping
cin
parents: 249
diff changeset
220 Safe.ArgumentNotNull(that, nameof(that));
7d52dc684bbd PollingComponent: implemented correct stopping
cin
parents: 249
diff changeset
221 return new PromiseAwaiter<T>(that);
7d52dc684bbd PollingComponent: implemented correct stopping
cin
parents: 249
diff changeset
222 }
249
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
223
72
d67b95eddaf4 promises refactoring
cin
parents:
diff changeset
224 }
d67b95eddaf4 promises refactoring
cin
parents:
diff changeset
225 }
d67b95eddaf4 promises refactoring
cin
parents:
diff changeset
226