Mercurial > pub > ImplabNet
annotate Implab/SyncContextPromise.cs @ 145:706fccb85524 v2
RC: cancellation support for promises + tests
author | cin |
---|---|
date | Sun, 08 Mar 2015 02:52:27 +0300 |
parents | f75cfa58e3d4 |
children | 97fbbf816844 |
rev | line source |
---|---|
72 | 1 using System.Threading; |
138
f75cfa58e3d4
added ICancellable.Cancel(Exception) to allow specify the reason of cancellation
cin
parents:
119
diff
changeset
|
2 using System; |
72 | 3 |
4 namespace Implab { | |
5 public class SyncContextPromise<T> : Promise<T> { | |
6 readonly SynchronizationContext m_context; | |
7 | |
8 public SyncContextPromise(SynchronizationContext context) { | |
9 Safe.ArgumentNotNull(context, "context"); | |
10 m_context = context; | |
11 } | |
12 | |
145 | 13 protected override void SignalSuccess(Promise<T>.HandlerDescriptor handler) { |
119
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
106
diff
changeset
|
14 m_context.Post(x => base.SignalSuccess(handler), null); |
72 | 15 } |
119
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
106
diff
changeset
|
16 |
145 | 17 protected override void SignalError(Promise<T>.HandlerDescriptor handler, Exception error) { |
119
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
106
diff
changeset
|
18 m_context.Post(x => base.SignalError(handler, error), null); |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
106
diff
changeset
|
19 } |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
106
diff
changeset
|
20 |
145 | 21 protected override void SignalCancelled(Promise<T>.HandlerDescriptor handler, Exception reason) { |
138
f75cfa58e3d4
added ICancellable.Cancel(Exception) to allow specify the reason of cancellation
cin
parents:
119
diff
changeset
|
22 m_context.Post(x => base.SignalCancelled(handler, reason), null); |
72 | 23 } |
24 } | |
25 } | |
26 |