annotate Implab.Fx/PromiseHelpers.cs @ 76:c761fc982e1d v2

Refactoring of the IPromise<T> interface Added tests
author cin
date Wed, 10 Sep 2014 17:53:05 +0400
parents d67b95eddaf4
children b4c4d65b7def
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
1 using System;
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
2 using System.Windows.Forms;
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
3 using System.Threading;
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
4
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
5 namespace Implab.Fx
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
6 {
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
7 public static class PromiseHelpers
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
8 {
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
9 /// <summary>
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
10 /// Перенаправляет обработку обещания в поток указанного элемента управления.
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
11 /// </summary>
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
12 /// <typeparam name="T">Тип результата обещания</typeparam>
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
13 /// <param name="that">Исходное обещание</param>
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
14 /// <param name="ctl">Элемент управления</param>
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
15 /// <returns>Новое обещание, обработчики которого будут выполнены в потоке элемента управления.</returns>
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
16 /// <exception cref="ArgumentNullException">Параметр не может быть <c>null</c>.</exception>
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
17 /// <example>
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
18 /// client
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
19 /// .Get("description.txt") // returns a promise
76
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 72
diff changeset
20 /// .DispatchToControl(m_ctl) // handle the promise in the thread of the control
4
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
21 /// .Then(
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
22 /// description => m_ctl.Text = description // now it's safe
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
23 /// )
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
24 /// </example>
76
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 72
diff changeset
25 public static IPromise<T> DispatchToControl<T>(this IPromise<T> that, Control ctl)
4
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
26 {
76
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 72
diff changeset
27 Safe.ArgumentNotNull(that, "that");
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 72
diff changeset
28 Safe.ArgumentNotNull(ctl, "ctl");
4
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
29
72
d67b95eddaf4 promises refactoring
cin
parents: 4
diff changeset
30 var directed = new ControlBoundPromise<T>(ctl,that,true);
4
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
31
76
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 72
diff changeset
32 that.Last(
72
d67b95eddaf4 promises refactoring
cin
parents: 4
diff changeset
33 directed.Resolve,
76
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 72
diff changeset
34 directed.Reject,
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 72
diff changeset
35 directed.Cancel
4
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
36 );
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
37
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
38 return directed;
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
39 }
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
40 }
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
41 }