Mercurial > pub > ImplabNet
annotate Implab/PromiseExtensions.cs @ 248:5cb4826c2c2a v3
Added awaiters to promises
Added static methods to Promise Resolve, Reject, All.
Updated promise helpers
author | cin |
---|---|
date | Tue, 30 Jan 2018 01:37:17 +0300 |
parents | a867536c68fc |
children | d82909310094 |
rev | line source |
---|---|
72 | 1 using System.Threading; |
75 | 2 using System; |
109 | 3 using Implab.Diagnostics; |
119
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
110
diff
changeset
|
4 using System.Collections.Generic; |
248 | 5 using System.Linq; |
6 | |
72 | 7 namespace Implab { |
8 public static class PromiseExtensions { | |
9 | |
248 | 10 public static IPromise Then(this IPromise that, Action fulfilled, Action<Exception> rejected) { |
11 var reaction = new PromiseActionReaction(fulfilled, rejected, Promise.DefaultDispatcher); | |
12 that.Then(reaction); | |
13 return reaction.Promise; | |
101 | 14 } |
15 | |
248 | 16 public static IPromise Then(this IPromise that, Action fulfilled, Func<Exception, IPromise> rejected) { |
17 var reaction = new PromiseActionReaction(fulfilled, rejected, Promise.DefaultDispatcher); | |
18 that.Then(reaction); | |
19 return reaction.Promise; | |
207
558f34b2fb50
added Safe.DispatchEvent() a legacy equivalent for '?.Invoke()'
cin
parents:
205
diff
changeset
|
20 } |
558f34b2fb50
added Safe.DispatchEvent() a legacy equivalent for '?.Invoke()'
cin
parents:
205
diff
changeset
|
21 |
248 | 22 public static IPromise Then(this IPromise that, Func<IPromise> fulfilled, Action<Exception> rejected) { |
23 var reaction = new PromiseActionReaction(fulfilled, rejected, Promise.DefaultDispatcher); | |
24 that.Then(reaction); | |
25 return reaction.Promise; | |
75 | 26 } |
110 | 27 |
248 | 28 public static IPromise Then(this IPromise that, Func<IPromise> fulfilled, Func<Exception, IPromise> rejected) { |
29 var reaction = new PromiseActionReaction(fulfilled, rejected, Promise.DefaultDispatcher); | |
30 that.Then(reaction); | |
31 return reaction.Promise; | |
110 | 32 } |
119
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
110
diff
changeset
|
33 |
248 | 34 public static IPromise Then<T>(this IPromise<T> that, Action<T> fulfilled, Action<Exception> rejected) { |
35 var reaction = new PromiseActionReaction<T>(fulfilled, rejected, Promise.DefaultDispatcher); | |
36 that.Then(reaction); | |
37 return reaction.Promise; | |
205
8200ab154c8a
Added ResetState to RunnableComponent to reset in case of failure
cin
parents:
185
diff
changeset
|
38 } |
8200ab154c8a
Added ResetState to RunnableComponent to reset in case of failure
cin
parents:
185
diff
changeset
|
39 |
248 | 40 public static IPromise Then<T>(this IPromise<T> that, Action<T> fulfilled, Func<Exception, IPromise> rejected) { |
41 var reaction = new PromiseActionReaction<T>(fulfilled, rejected, Promise.DefaultDispatcher); | |
42 that.Then(reaction); | |
43 return reaction.Promise; | |
208
7d07503621fe
RunnableComponent.Dispose(bool,Exception) changed to standart Dispose(bool)
cin
parents:
207
diff
changeset
|
44 } |
7d07503621fe
RunnableComponent.Dispose(bool,Exception) changed to standart Dispose(bool)
cin
parents:
207
diff
changeset
|
45 |
248 | 46 public static IPromise Then<T>(this IPromise<T> that, Func<T, IPromise> fulfilled, Action<Exception> rejected) { |
47 var reaction = new PromiseActionReaction<T>(fulfilled, rejected, Promise.DefaultDispatcher); | |
48 that.Then(reaction); | |
49 return reaction.Promise; | |
124 | 50 } |
145 | 51 |
248 | 52 public static IPromise Then<T>(this IPromise<T> that, Func<T, IPromise> fulfilled, Func<Exception, IPromise> rejected) { |
53 var reaction = new PromiseActionReaction<T>(fulfilled, rejected, Promise.DefaultDispatcher); | |
54 that.Then(reaction); | |
55 return reaction.Promise; | |
56 } | |
145 | 57 |
248 | 58 public static IPromise<Tout> Then<Tout>(this IPromise that, Func<Tout> fulfilled, Func<Exception, Tout> rejected) { |
59 var reaction = new PromiseFuncReaction<Tout>(fulfilled, rejected, Promise.DefaultDispatcher); | |
60 that.Then(reaction); | |
61 return reaction.Promise; | |
145 | 62 } |
63 | |
248 | 64 public static IPromise<Tout> Then<Tout>(this IPromise that, Func<Tout> fulfilled, Func<Exception, IPromise<Tout>> rejected) { |
65 var reaction = new PromiseFuncReaction<Tout>(fulfilled, rejected, Promise.DefaultDispatcher); | |
66 that.Then(reaction); | |
67 return reaction.Promise; | |
145 | 68 } |
69 | |
248 | 70 public static IPromise<Tout> Then<Tout>(this IPromise that, Func<IPromise<Tout>> fulfilled, Func<Exception, Tout> rejected) { |
71 var reaction = new PromiseFuncReaction<Tout>(fulfilled, rejected, Promise.DefaultDispatcher); | |
72 that.Then(reaction); | |
73 return reaction.Promise; | |
207
558f34b2fb50
added Safe.DispatchEvent() a legacy equivalent for '?.Invoke()'
cin
parents:
205
diff
changeset
|
74 } |
558f34b2fb50
added Safe.DispatchEvent() a legacy equivalent for '?.Invoke()'
cin
parents:
205
diff
changeset
|
75 |
248 | 76 public static IPromise<Tout> Then<Tout>(this IPromise that, Func<IPromise<Tout>> fulfilled, Func<Exception, IPromise<Tout>> rejected) { |
77 var reaction = new PromiseFuncReaction<Tout>(fulfilled, rejected, Promise.DefaultDispatcher); | |
78 that.Then(reaction); | |
79 return reaction.Promise; | |
145 | 80 } |
81 | |
248 | 82 public static IPromise<Tout> Then<Tin, Tout>(this IPromise<Tin> that, Func<Tin, Tout> fulfilled, Func<Exception, Tout> rejected) { |
83 var reaction = new PromiseFuncReaction<Tin, Tout>(fulfilled, rejected, Promise.DefaultDispatcher); | |
84 that.Then(reaction); | |
85 return reaction.Promise; | |
207
558f34b2fb50
added Safe.DispatchEvent() a legacy equivalent for '?.Invoke()'
cin
parents:
205
diff
changeset
|
86 } |
558f34b2fb50
added Safe.DispatchEvent() a legacy equivalent for '?.Invoke()'
cin
parents:
205
diff
changeset
|
87 |
248 | 88 public static IPromise<Tout> Then<Tin, Tout>(this IPromise<Tin> that, Func<Tin, Tout> fulfilled, Func<Exception, IPromise<Tout>> rejected) { |
89 var reaction = new PromiseFuncReaction<Tin, Tout>(fulfilled, rejected, Promise.DefaultDispatcher); | |
90 that.Then(reaction); | |
91 return reaction.Promise; | |
207
558f34b2fb50
added Safe.DispatchEvent() a legacy equivalent for '?.Invoke()'
cin
parents:
205
diff
changeset
|
92 } |
558f34b2fb50
added Safe.DispatchEvent() a legacy equivalent for '?.Invoke()'
cin
parents:
205
diff
changeset
|
93 |
248 | 94 public static IPromise<Tout> Then<Tin, Tout>(this IPromise<Tin> that, Func<Tin, IPromise<Tout>> fulfilled, Func<Exception, Tout> rejected) { |
95 var reaction = new PromiseFuncReaction<Tin, Tout>(fulfilled, rejected, Promise.DefaultDispatcher); | |
96 that.Then(reaction); | |
97 return reaction.Promise; | |
207
558f34b2fb50
added Safe.DispatchEvent() a legacy equivalent for '?.Invoke()'
cin
parents:
205
diff
changeset
|
98 } |
558f34b2fb50
added Safe.DispatchEvent() a legacy equivalent for '?.Invoke()'
cin
parents:
205
diff
changeset
|
99 |
248 | 100 public static IPromise<Tout> Then<Tin, Tout>(this IPromise<Tin> that, Func<Tin, IPromise<Tout>> fulfilled, Func<Exception, IPromise<Tout>> rejected) { |
101 var reaction = new PromiseFuncReaction<Tin, Tout>(fulfilled, rejected, Promise.DefaultDispatcher); | |
102 that.Then(reaction); | |
103 return reaction.Promise; | |
145 | 104 } |
105 | |
248 | 106 public static IPromise Catch(this IPromise that, Action<Exception> rejected) { |
107 return Then(that, null, rejected); | |
145 | 108 } |
109 | |
248 | 110 public static IPromise Catch(this IPromise that, Func<Exception, IPromise> rejected) { |
111 return Then(that, null, rejected); | |
145 | 112 } |
113 | |
248 | 114 public static IPromise<Tout> Catch<Tout>(this IPromise that, Func<Exception, Tout> rejected) { |
115 return Then(that, (Func<Tout>)null, rejected); | |
145 | 116 } |
117 | |
248 | 118 public static IPromise<Tout> Catch<Tout>(this IPromise that, Func<Exception, IPromise<Tout>> rejected) { |
119 return Then(that, (Func<Tout>)null, rejected); | |
120 } | |
75 | 121 |
248 | 122 public static IPromise<Tout> Catch<Tin, Tout>(this IPromise<Tin> that, Func<Exception, Tout> rejected) { |
123 return Then(that, (Func<Tin, Tout>)null, rejected); | |
124 } | |
208
7d07503621fe
RunnableComponent.Dispose(bool,Exception) changed to standart Dispose(bool)
cin
parents:
207
diff
changeset
|
125 |
248 | 126 public static IPromise<Tout> Catch<Tin, Tout>(this IPromise<Tin> that, Func<Exception, IPromise<Tout>> rejected) { |
127 return Then(that, (Func<Tin, Tout>)null, rejected); | |
128 } | |
72 | 129 } |
130 } | |
131 |