annotate Implab.Fx/PromiseHelpers.cs @ 196:40d7fed4a09e

fixed promise chaining behavior, the error handler doesn't handle result or cancellation handlers exceptions these exceptions are propagated to the next handlers.
author cin
date Mon, 29 Aug 2016 23:15:51 +0300
parents 2573b562e328
children
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
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
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
33
104
5f10d54b45df renamed Promise.Last -> Promise.On
cin
parents: 102
diff changeset
34 that.On(
72
d67b95eddaf4 promises refactoring
cin
parents: 4
diff changeset
35 directed.Resolve,
76
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 72
diff changeset
36 directed.Reject,
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 72
diff changeset
37 directed.Cancel
4
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
38 );
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
39
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
40 return directed;
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
41 }
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
42 }
381095ad0a69 Implab.Fx: implemented animation object
cin
parents:
diff changeset
43 }