Mercurial > pub > ImplabNet
annotate Implab.Fx/PromiseHelpers.cs @ 190:1c2a16d071a7 v2
Слияние с ref20160224
author | cin |
---|---|
date | Fri, 22 Apr 2016 13:08:08 +0300 |
parents | 2573b562e328 |
children |
rev | line source |
---|---|
4 | 1 using System; |
2 using System.Windows.Forms; | |
3 using System.Threading; | |
4 | |
5 namespace Implab.Fx | |
6 { | |
7 public static class PromiseHelpers | |
8 { | |
9 /// <summary> | |
10 /// Перенаправляет обработку обещания в поток указанного элемента управления. | |
11 /// </summary> | |
12 /// <typeparam name="T">Тип результата обещания</typeparam> | |
13 /// <param name="that">Исходное обещание</param> | |
14 /// <param name="ctl">Элемент управления</param> | |
15 /// <returns>Новое обещание, обработчики которого будут выполнены в потоке элемента управления.</returns> | |
16 /// <exception cref="ArgumentNullException">Параметр не может быть <c>null</c>.</exception> | |
17 /// <example> | |
18 /// client | |
19 /// .Get("description.txt") // returns a promise | |
76 | 20 /// .DispatchToControl(m_ctl) // handle the promise in the thread of the control |
4 | 21 /// .Then( |
22 /// description => m_ctl.Text = description // now it's safe | |
23 /// ) | |
24 /// </example> | |
76 | 25 public static IPromise<T> DispatchToControl<T>(this IPromise<T> that, Control ctl) |
4 | 26 { |
76 | 27 Safe.ArgumentNotNull(that, "that"); |
28 Safe.ArgumentNotNull(ctl, "ctl"); | |
4 | 29 |
119
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
30 var directed = new ControlBoundPromise<T>(ctl); |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
31 |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
32 directed.On(that.Cancel, PromiseEventType.Cancelled); |
4 | 33 |
104 | 34 that.On( |
72 | 35 directed.Resolve, |
76 | 36 directed.Reject, |
37 directed.Cancel | |
4 | 38 ); |
39 | |
40 return directed; | |
41 } | |
42 } | |
43 } |