@@ -1,86 +1,86 | |||||
1 | using System; |
|
1 | using System; | |
2 | using System.Collections.Generic; |
|
2 | using System.Collections.Generic; | |
3 | using System.Linq; |
|
3 | using System.Linq; | |
4 | using System.Text; |
|
4 | using System.Text; | |
5 |
|
5 | |||
6 | namespace Implab { |
|
6 | namespace Implab { | |
7 | public interface IPromise: ICancellable { |
|
7 | public interface IPromise: ICancellable { | |
8 | /// <summary> |
|
8 | /// <summary> | |
9 | /// Check whereather the promise has no more than one dependent promise. |
|
9 | /// Check whereather the promise has no more than one dependent promise. | |
10 | /// </summary> |
|
10 | /// </summary> | |
11 | bool IsExclusive { |
|
11 | bool IsExclusive { | |
12 | get; |
|
12 | get; | |
13 | } |
|
13 | } | |
14 |
|
14 | |||
15 | /// <summary> |
|
15 | /// <summary> | |
16 | /// Π’ΠΈΠΏ ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΠ°, ΠΏΠΎΠ»ΡΡΠ°Π΅ΠΌΠΎΠ³ΠΎ ΡΠ΅ΡΠ΅Π· Π΄Π°Π½Π½ΠΎΠ΅ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅. |
|
16 | /// Π’ΠΈΠΏ ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΠ°, ΠΏΠΎΠ»ΡΡΠ°Π΅ΠΌΠΎΠ³ΠΎ ΡΠ΅ΡΠ΅Π· Π΄Π°Π½Π½ΠΎΠ΅ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅. | |
17 | /// </summary> |
|
17 | /// </summary> | |
18 | Type PromiseType { get; } |
|
18 | Type PromiseType { get; } | |
19 |
|
19 | |||
20 | /// <summary> |
|
20 | /// <summary> | |
21 | /// ΠΠ±Π΅ΡΠ°Π½ΠΈΠ΅ ΡΠ²Π»ΡΠ΅ΡΡΡ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΡΠΌ, Π»ΠΈΠ±ΠΎ ΡΡΠΏΠ΅ΡΠ½ΠΎ, Π»ΠΈΠ±ΠΎ Ρ ΠΎΡΠΈΠ±ΠΊΠΎΠΉ. |
|
21 | /// ΠΠ±Π΅ΡΠ°Π½ΠΈΠ΅ ΡΠ²Π»ΡΠ΅ΡΡΡ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΡΠΌ, Π»ΠΈΠ±ΠΎ ΡΡΠΏΠ΅ΡΠ½ΠΎ, Π»ΠΈΠ±ΠΎ Ρ ΠΎΡΠΈΠ±ΠΊΠΎΠΉ, Π»ΠΈΠ±ΠΎ ΠΎΡΠΌΠ΅Π½Π΅Π½ΠΎ. | |
22 | /// </summary> |
|
22 | /// </summary> | |
23 | bool IsResolved { get; } |
|
23 | bool IsResolved { get; } | |
24 |
|
24 | |||
25 | /// <summary> |
|
25 | /// <summary> | |
26 | /// ΠΠ±Π΅ΡΠ°Π½ΠΈΠ΅ Π±ΡΠ»ΠΎ ΠΎΡΠΌΠ΅Π½Π΅Π½ΠΎ. |
|
26 | /// ΠΠ±Π΅ΡΠ°Π½ΠΈΠ΅ Π±ΡΠ»ΠΎ ΠΎΡΠΌΠ΅Π½Π΅Π½ΠΎ. | |
27 | /// </summary> |
|
27 | /// </summary> | |
28 | bool IsCancelled { get; } |
|
28 | bool IsCancelled { get; } | |
29 |
|
29 | |||
30 | IPromise Then(Action success, ErrorHandler error, Action cancel); |
|
30 | IPromise Then(Action success, ErrorHandler error, Action cancel); | |
31 | IPromise Then(Action success, ErrorHandler error); |
|
31 | IPromise Then(Action success, ErrorHandler error); | |
32 | IPromise Then(Action success); |
|
32 | IPromise Then(Action success); | |
33 |
|
33 | |||
34 | IPromise Chain(Func<IPromise> chained, ErrorHandler<IPromise> error, Action cancel); |
|
34 | IPromise Chain(Func<IPromise> chained, ErrorHandler<IPromise> error, Action cancel); | |
35 | IPromise Chain(Func<IPromise> chained, ErrorHandler<IPromise> error); |
|
35 | IPromise Chain(Func<IPromise> chained, ErrorHandler<IPromise> error); | |
36 | IPromise Chain(Func<IPromise> chained); |
|
36 | IPromise Chain(Func<IPromise> chained); | |
37 |
|
37 | |||
38 | /// <summary> |
|
38 | /// <summary> | |
39 | /// ΠΠΎΠ±Π°Π²Π»ΡΠ΅Ρ ΠΏΠΎΡΠ»Π΅Π΄Π½ΠΉ ΠΎΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊ Π² ΡΠ΅ΠΏΠΎΡΠΊΡ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠΉ, Π½Π΅ ΡΠΎΠ·Π΄Π°Π΅Ρ ΠΏΡΠΎΠΌΠ΅ΠΆΡΡΠΎΡΠ½ΡΡ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠΉ. |
|
39 | /// ΠΠΎΠ±Π°Π²Π»ΡΠ΅Ρ ΠΏΠΎΡΠ»Π΅Π΄Π½ΠΉ ΠΎΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊ Π² ΡΠ΅ΠΏΠΎΡΠΊΡ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠΉ, Π½Π΅ ΡΠΎΠ·Π΄Π°Π΅Ρ ΠΏΡΠΎΠΌΠ΅ΠΆΡΡΠΎΡΠ½ΡΡ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠΉ. | |
40 | /// </summary> |
|
40 | /// </summary> | |
41 | /// <param name="success">Success.</param> |
|
41 | /// <param name="success">Success.</param> | |
42 | /// <param name="error">Error.</param> |
|
42 | /// <param name="error">Error.</param> | |
43 | /// <param name="cancel">Cancel.</param> |
|
43 | /// <param name="cancel">Cancel.</param> | |
44 | void Last(Action success, ErrorHandler error, Action cancel); |
|
44 | void Last(Action success, ErrorHandler error, Action cancel); | |
45 | void Last(Action success, ErrorHandler error); |
|
45 | void Last(Action success, ErrorHandler error); | |
46 | void Last(Action success); |
|
46 | void Last(Action success); | |
47 |
|
47 | |||
48 | IPromise Error(ErrorHandler error); |
|
48 | IPromise Error(ErrorHandler error); | |
49 | /// <summary> |
|
49 | /// <summary> | |
50 | /// ΠΠ±ΡΠ°Π±Π°ΡΡΠ²Π°Π΅Ρ Π»ΠΈΠ±ΠΎ ΠΎΡΠΈΠ±ΠΊΡ, Π»ΠΈΠ±ΠΎ ΡΠ΅Π·ΡΠ»ΡΡΠ°Ρ. Π‘ΠΎΠ±ΡΡΠΈΠ΅ ΠΎΡΠΌΠ΅Π½Ρ Π½Π΅ ΠΎΠ±ΡΠ°Π±Π°ΡΡΠ²Π°Π΅ΡΡΡ. |
|
50 | /// ΠΠ±ΡΠ°Π±Π°ΡΡΠ²Π°Π΅Ρ Π»ΠΈΠ±ΠΎ ΠΎΡΠΈΠ±ΠΊΡ, Π»ΠΈΠ±ΠΎ ΡΠ΅Π·ΡΠ»ΡΡΠ°Ρ. Π‘ΠΎΠ±ΡΡΠΈΠ΅ ΠΎΡΠΌΠ΅Π½Ρ Π½Π΅ ΠΎΠ±ΡΠ°Π±Π°ΡΡΠ²Π°Π΅ΡΡΡ. | |
51 | /// </summary> |
|
51 | /// </summary> | |
52 | /// <param name="handler">ΠΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊ.</param> |
|
52 | /// <param name="handler">ΠΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊ.</param> | |
53 | /// <remarks>ΠΠΎΡΠ»Π΅ ΠΎΠ±ΡΠ°Π±ΠΎΡΠΊΠ΅ ΠΎΡΠΈΠ±ΠΊΠΈ, ΠΎΠ½Π° ΠΏΠ΅ΡΠ΅Π΄Π°Π΅ΡΡΡ Π΄Π°Π»ΡΡΠ΅.</remarks> |
|
53 | /// <remarks>ΠΠΎΡΠ»Π΅ ΠΎΠ±ΡΠ°Π±ΠΎΡΠΊΠ΅ ΠΎΡΠΈΠ±ΠΊΠΈ, ΠΎΠ½Π° ΠΏΠ΅ΡΠ΅Π΄Π°Π΅ΡΡΡ Π΄Π°Π»ΡΡΠ΅.</remarks> | |
54 | /// <summary> |
|
54 | /// <summary> | |
55 | /// ΠΠ±ΡΠ°Π±Π°ΡΡΠ²Π°Π΅Ρ Π»ΠΈΠ±ΠΎ ΠΎΡΠΈΠ±ΠΊΡ, Π»ΠΈΠ±ΠΎ ΡΠ΅Π·ΡΠ»ΡΡΠ°Ρ, Π»ΠΈΠ±ΠΎ ΠΎΡΠΌΠ΅Π½Ρ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ. |
|
55 | /// ΠΠ±ΡΠ°Π±Π°ΡΡΠ²Π°Π΅Ρ Π»ΠΈΠ±ΠΎ ΠΎΡΠΈΠ±ΠΊΡ, Π»ΠΈΠ±ΠΎ ΡΠ΅Π·ΡΠ»ΡΡΠ°Ρ, Π»ΠΈΠ±ΠΎ ΠΎΡΠΌΠ΅Π½Ρ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ. | |
56 | /// </summary> |
|
56 | /// </summary> | |
57 | /// <param name="handler">ΠΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊ.</param> |
|
57 | /// <param name="handler">ΠΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊ.</param> | |
58 | /// <remarks>ΠΠΎΡΠ»Π΅ ΠΎΠ±ΡΠ°Π±ΠΎΡΠΊΠ΅ ΠΎΡΠΈΠ±ΠΊΠΈ, ΠΎΠ½Π° ΠΏΠ΅ΡΠ΅Π΄Π°Π΅ΡΡΡ Π΄Π°Π»ΡΡΠ΅.</remarks> |
|
58 | /// <remarks>ΠΠΎΡΠ»Π΅ ΠΎΠ±ΡΠ°Π±ΠΎΡΠΊΠ΅ ΠΎΡΠΈΠ±ΠΊΠΈ, ΠΎΠ½Π° ΠΏΠ΅ΡΠ΅Π΄Π°Π΅ΡΡΡ Π΄Π°Π»ΡΡΠ΅.</remarks> | |
59 | IPromise Anyway(Action handler); |
|
59 | IPromise Anyway(Action handler); | |
60 | /// <summary> |
|
60 | /// <summary> | |
61 | /// ΠΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊ Π΄Π»Ρ ΡΠ΅Π³ΠΈΡΡΡΠ°ΡΠΈΠΈ ΠΎΡΠΌΠ΅Π½Ρ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ, ΡΠΎΠ±ΡΡΠΈΠ΅ ΠΎΡΠΌΠ΅Π½Ρ Π½Π΅ ΠΌΠΎΠΆΠ΅Ρ Π±ΡΡΡ ΠΏΠΎΠ΄Π°Π²Π»Π΅Π½ΠΎ. |
|
61 | /// ΠΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊ Π΄Π»Ρ ΡΠ΅Π³ΠΈΡΡΡΠ°ΡΠΈΠΈ ΠΎΡΠΌΠ΅Π½Ρ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ, ΡΠΎΠ±ΡΡΠΈΠ΅ ΠΎΡΠΌΠ΅Π½Ρ Π½Π΅ ΠΌΠΎΠΆΠ΅Ρ Π±ΡΡΡ ΠΏΠΎΠ΄Π°Π²Π»Π΅Π½ΠΎ. | |
62 | /// </summary> |
|
62 | /// </summary> | |
63 | /// <returns>ΠΠΎΠ²ΠΎΠ΅ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅, ΡΠ²ΡΠ·Π°Π½Π½ΠΎΠ΅ Ρ ΡΠ΅ΠΊΡΡΠΈΠΌ.</returns> |
|
63 | /// <returns>ΠΠΎΠ²ΠΎΠ΅ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅, ΡΠ²ΡΠ·Π°Π½Π½ΠΎΠ΅ Ρ ΡΠ΅ΠΊΡΡΠΈΠΌ.</returns> | |
64 | /// <param name="handler">ΠΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊ ΡΠΎΠ±ΡΡΠΈΡ.</param> |
|
64 | /// <param name="handler">ΠΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊ ΡΠΎΠ±ΡΡΠΈΡ.</param> | |
65 | /// <remarks>ΠΡΠ»ΠΈ ΠΎΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊ Π²ΡΠ·ΡΠ²Π°Π΅Ρ ΠΈΡΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅, ΡΠΎ ΠΎΠ½ΠΎ ΠΏΠ΅ΡΠ΅Π΄Π°Π΅ΡΡΡ ΠΎΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊΡ ΠΎΡΠΈΠ±ΠΊΠΈ, ΡΠ΅Π·ΡΠ»ΡΡΠ°Ρ ΡΠ°Π±ΠΎΡΡ |
|
65 | /// <remarks>ΠΡΠ»ΠΈ ΠΎΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊ Π²ΡΠ·ΡΠ²Π°Π΅Ρ ΠΈΡΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅, ΡΠΎ ΠΎΠ½ΠΎ ΠΏΠ΅ΡΠ΅Π΄Π°Π΅ΡΡΡ ΠΎΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊΡ ΠΎΡΠΈΠ±ΠΊΠΈ, ΡΠ΅Π·ΡΠ»ΡΡΠ°Ρ ΡΠ°Π±ΠΎΡΡ | |
66 | /// ΠΊΠΎΡΠΎΡΠΎΠ³ΠΎ Π±ΡΠ΄Π΅Ρ ΠΏΠ΅ΡΠ΅Π΄Π°Π½ ΡΠ²ΡΠ·Π°Π½Π½ΠΎΠΌΡ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ</remarks> |
|
66 | /// ΠΊΠΎΡΠΎΡΠΎΠ³ΠΎ Π±ΡΠ΄Π΅Ρ ΠΏΠ΅ΡΠ΅Π΄Π°Π½ ΡΠ²ΡΠ·Π°Π½Π½ΠΎΠΌΡ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ</remarks> | |
67 | IPromise Cancelled(Action handler); |
|
67 | IPromise Cancelled(Action handler); | |
68 |
|
68 | |||
69 | /// <summary> |
|
69 | /// <summary> | |
70 | /// ΠΡΠ΅ΠΎΠ±ΡΠ°Π·ΡΠ΅Ρ ΡΠ΅Π·ΡΠ»ΡΡΠ°Ρ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ ΠΊ Π·Π°Π΄Π°Π½Π½ΠΎΠΌΡ ΡΠΈΠΏΡ ΠΈ Π²ΠΎΠ·Π²ΡΠ°ΡΠ°Π΅Ρ Π½ΠΎΠ²ΠΎΠ΅ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅. |
|
70 | /// ΠΡΠ΅ΠΎΠ±ΡΠ°Π·ΡΠ΅Ρ ΡΠ΅Π·ΡΠ»ΡΡΠ°Ρ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ ΠΊ Π·Π°Π΄Π°Π½Π½ΠΎΠΌΡ ΡΠΈΠΏΡ ΠΈ Π²ΠΎΠ·Π²ΡΠ°ΡΠ°Π΅Ρ Π½ΠΎΠ²ΠΎΠ΅ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅. | |
71 | /// </summary> |
|
71 | /// </summary> | |
72 | IPromise<T> Cast<T>(); |
|
72 | IPromise<T> Cast<T>(); | |
73 |
|
73 | |||
74 | /// <summary> |
|
74 | /// <summary> | |
75 | /// Π‘ΠΈΠ½Ρ ΡΠΎΠ½ΠΈΠ·ΠΈΡΡΠ΅Ρ ΡΠ΅ΠΊΡΡΠΈΠΉ ΠΏΠΎΡΠΎΠΊ Ρ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅ΠΌ. |
|
75 | /// Π‘ΠΈΠ½Ρ ΡΠΎΠ½ΠΈΠ·ΠΈΡΡΠ΅Ρ ΡΠ΅ΠΊΡΡΠΈΠΉ ΠΏΠΎΡΠΎΠΊ Ρ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅ΠΌ. | |
76 | /// </summary> |
|
76 | /// </summary> | |
77 | void Join(); |
|
77 | void Join(); | |
78 | /// <summary> |
|
78 | /// <summary> | |
79 | /// Π‘ΠΈΠ½Ρ ΡΠΎΠ½ΠΈΠ·ΠΈΡΡΠ΅Ρ ΡΠ΅ΠΊΡΡΠΈΠΉ ΠΏΠΎΡΠΎΠΊ Ρ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅ΠΌ. |
|
79 | /// Π‘ΠΈΠ½Ρ ΡΠΎΠ½ΠΈΠ·ΠΈΡΡΠ΅Ρ ΡΠ΅ΠΊΡΡΠΈΠΉ ΠΏΠΎΡΠΎΠΊ Ρ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅ΠΌ. | |
80 | /// </summary> |
|
80 | /// </summary> | |
81 | /// <param name="timeout">ΠΡΠ΅ΠΌΡ ΠΎΠΆΠΈΠ΄Π°Π½ΠΈΡ, ΠΏΠΎ Π΅Π³ΠΎ ΠΈΡΡΠ΅ΡΠ΅Π½ΠΈΡ Π²ΠΎΠ·Π½ΠΈΠΊΠ½Π΅Ρ ΠΈΡΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅.</param> |
|
81 | /// <param name="timeout">ΠΡΠ΅ΠΌΡ ΠΎΠΆΠΈΠ΄Π°Π½ΠΈΡ, ΠΏΠΎ Π΅Π³ΠΎ ΠΈΡΡΠ΅ΡΠ΅Π½ΠΈΡ Π²ΠΎΠ·Π½ΠΈΠΊΠ½Π΅Ρ ΠΈΡΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅.</param> | |
82 | /// <exception cref="TimeoutException">ΠΡΠ΅Π²ΡΡΠ΅Π½ΠΎ Π²ΡΠ΅ΠΌΡ ΠΎΠΆΠΈΠ΄Π°Π½ΠΈΡ.</exception> |
|
82 | /// <exception cref="TimeoutException">ΠΡΠ΅Π²ΡΡΠ΅Π½ΠΎ Π²ΡΠ΅ΠΌΡ ΠΎΠΆΠΈΠ΄Π°Π½ΠΈΡ.</exception> | |
83 | void Join(int timeout); |
|
83 | void Join(int timeout); | |
84 |
|
84 | |||
85 | } |
|
85 | } | |
86 | } |
|
86 | } |
@@ -1,914 +1,914 | |||||
1 | using System; |
|
1 | using System; | |
2 | using System.Collections.Generic; |
|
2 | using System.Collections.Generic; | |
3 | using System.Reflection; |
|
3 | using System.Reflection; | |
4 | using System.Diagnostics; |
|
4 | using System.Diagnostics; | |
5 | using System.Threading; |
|
5 | using System.Threading; | |
6 | using Implab.Parallels; |
|
6 | using Implab.Parallels; | |
7 |
|
7 | |||
8 | namespace Implab { |
|
8 | namespace Implab { | |
9 |
|
9 | |||
10 | public delegate void ErrorHandler(Exception e); |
|
10 | public delegate void ErrorHandler(Exception e); | |
11 | public delegate T ErrorHandler<out T>(Exception e); |
|
11 | public delegate T ErrorHandler<out T>(Exception e); | |
12 | public delegate void ResultHandler<in T>(T result); |
|
12 | public delegate void ResultHandler<in T>(T result); | |
13 | public delegate TNew ResultMapper<in TSrc,out TNew>(TSrc result); |
|
13 | public delegate TNew ResultMapper<in TSrc,out TNew>(TSrc result); | |
14 |
|
14 | |||
15 | /// <summary> |
|
15 | /// <summary> | |
16 | /// ΠΠ»Π°ΡΡ Π΄Π»Ρ Π°ΡΠΈΠ½Ρ ΡΠΎΠ½Π½ΠΎΠ³ΠΎ ΠΏΠΎΠ»ΡΡΠ΅Π½ΠΈΡ ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΠΎΠ². Π’Π°ΠΊ Π½Π°Π·ΡΠ²Π°Π΅ΠΌΠΎΠ΅ "ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅". |
|
16 | /// ΠΠ»Π°ΡΡ Π΄Π»Ρ Π°ΡΠΈΠ½Ρ ΡΠΎΠ½Π½ΠΎΠ³ΠΎ ΠΏΠΎΠ»ΡΡΠ΅Π½ΠΈΡ ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΠΎΠ². Π’Π°ΠΊ Π½Π°Π·ΡΠ²Π°Π΅ΠΌΠΎΠ΅ "ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅". | |
17 | /// </summary> |
|
17 | /// </summary> | |
18 | /// <typeparam name="T">Π’ΠΈΠΏ ΠΏΠΎΠ»ΡΡΠ°Π΅ΠΌΠΎΠ³ΠΎ ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΠ°</typeparam> |
|
18 | /// <typeparam name="T">Π’ΠΈΠΏ ΠΏΠΎΠ»ΡΡΠ°Π΅ΠΌΠΎΠ³ΠΎ ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΠ°</typeparam> | |
19 | /// <remarks> |
|
19 | /// <remarks> | |
20 | /// <para>Π‘Π΅ΡΠ²ΠΈΡ ΠΏΡΠΈ ΠΎΠ±ΡΠ°ΡΠ΅Π½ΠΈΠΈ ΠΊ Π΅Π³ΠΎ ΠΌΠ΅ΡΠΎΠ΄Ρ Π΄Π°Π΅Ρ ΠΎΠ±Π΅ΡΠ°ΠΈΠ½ΠΈΠ΅ ΠΎ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΠΈ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ, |
|
20 | /// <para>Π‘Π΅ΡΠ²ΠΈΡ ΠΏΡΠΈ ΠΎΠ±ΡΠ°ΡΠ΅Π½ΠΈΠΈ ΠΊ Π΅Π³ΠΎ ΠΌΠ΅ΡΠΎΠ΄Ρ Π΄Π°Π΅Ρ ΠΎΠ±Π΅ΡΠ°ΠΈΠ½ΠΈΠ΅ ΠΎ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΠΈ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ, | |
21 | /// ΠΊΠ»ΠΈΠ΅Π½Ρ ΠΏΠΎΠ»ΡΡΠΈΠ² ΡΠ°ΠΊΠΎΠ΅ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅ ΠΌΠΎΠΆΠ΅Ρ ΡΡΡΠ°Π½ΠΎΠ²ΠΈΡΡ ΡΡΠ΄ ΠΎΠ±ΡΠ°ΡΠ½ΡΡ Π²ΡΠ·ΠΎΠ²ΠΎ Π΄Π»Ρ ΠΏΠΎΠ»ΡΡΠ΅Π½ΠΈΡ |
|
21 | /// ΠΊΠ»ΠΈΠ΅Π½Ρ ΠΏΠΎΠ»ΡΡΠΈΠ² ΡΠ°ΠΊΠΎΠ΅ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅ ΠΌΠΎΠΆΠ΅Ρ ΡΡΡΠ°Π½ΠΎΠ²ΠΈΡΡ ΡΡΠ΄ ΠΎΠ±ΡΠ°ΡΠ½ΡΡ Π²ΡΠ·ΠΎΠ²ΠΎ Π΄Π»Ρ ΠΏΠΎΠ»ΡΡΠ΅Π½ΠΈΡ | |
22 | /// ΡΠΎΠ±ΡΡΠΈΠΉ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΡ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ, ΡΠΎΠ΅ΡΡΡ Π·Π°Π²Π΅ΡΡΠ΅Π½ΠΈΡ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ ΠΈ ΠΏΡΠ΅Π΄ΠΎΡΡΠ°Π²Π»Π΅Π½ΠΈΠΈ ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΠΎΠ².</para> |
|
22 | /// ΡΠΎΠ±ΡΡΠΈΠΉ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΡ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ, ΡΠΎΠ΅ΡΡΡ Π·Π°Π²Π΅ΡΡΠ΅Π½ΠΈΡ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ ΠΈ ΠΏΡΠ΅Π΄ΠΎΡΡΠ°Π²Π»Π΅Π½ΠΈΠΈ ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΠΎΠ².</para> | |
23 | /// <para> |
|
23 | /// <para> | |
24 | /// ΠΠ±Π΅ΡΠ΅Π½ΠΈΠ΅ ΠΌΠΎΠΆΠ΅Ρ Π±ΡΡΡ ΠΊΠ°ΠΊ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΎ, ΡΠ°ΠΊ ΠΈ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΎ Ρ ΠΎΡΠΈΠ±ΠΊΠΎΠΉ. ΠΠ»Ρ ΠΏΠΎΠ΄ΠΏΠΈΡΠΊΠΈ Π½Π° |
|
24 | /// ΠΠ±Π΅ΡΠ΅Π½ΠΈΠ΅ ΠΌΠΎΠΆΠ΅Ρ Π±ΡΡΡ ΠΊΠ°ΠΊ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΎ, ΡΠ°ΠΊ ΠΈ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΎ Ρ ΠΎΡΠΈΠ±ΠΊΠΎΠΉ. ΠΠ»Ρ ΠΏΠΎΠ΄ΠΏΠΈΡΠΊΠΈ Π½Π° | |
25 | /// Π΄Π°Π½Π½ΡΠ΅ ΡΠΎΠ±ΡΡΠΈΡ ΠΊΠ»ΠΈΠ΅Π½Ρ Π΄ΠΎΠ»ΠΆΠ΅Π½ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΡ ΠΌΠ΅ΡΠΎΠ΄Ρ <c>Then</c>. |
|
25 | /// Π΄Π°Π½Π½ΡΠ΅ ΡΠΎΠ±ΡΡΠΈΡ ΠΊΠ»ΠΈΠ΅Π½Ρ Π΄ΠΎΠ»ΠΆΠ΅Π½ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΡ ΠΌΠ΅ΡΠΎΠ΄Ρ <c>Then</c>. | |
26 | /// </para> |
|
26 | /// </para> | |
27 | /// <para> |
|
27 | /// <para> | |
28 | /// Π‘Π΅ΡΠ²ΠΈΡ, Π² ΡΠ²ΠΎΡ ΠΎΡΠ΅ΡΠ΅Π΄Ρ, ΠΏΠΎ ΠΎΠΊΠΎΠ½ΡΠ°Π½ΠΈΡ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΡ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ (Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎ Ρ ΠΎΡΠΈΠ±ΠΊΠΎΠΉ), |
|
28 | /// Π‘Π΅ΡΠ²ΠΈΡ, Π² ΡΠ²ΠΎΡ ΠΎΡΠ΅ΡΠ΅Π΄Ρ, ΠΏΠΎ ΠΎΠΊΠΎΠ½ΡΠ°Π½ΠΈΡ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΡ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ (Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎ Ρ ΠΎΡΠΈΠ±ΠΊΠΎΠΉ), | |
29 | /// ΠΈΡΠΏΠΎΠ»ΡΠ·ΡΠ΅Ρ ΠΌΠ΅ΡΠΎΠ΄Ρ <c>Resolve</c> Π»ΠΈΠ±ΠΎ <c>Reject</c> Π΄Π»Ρ ΠΎΠΏΠΎΠ²Π΅ΡΠ΅Π½ΠΈΡ ΠΊΠ»ΠΈΠ΅ΡΠ½Π° ΠΎ |
|
29 | /// ΠΈΡΠΏΠΎΠ»ΡΠ·ΡΠ΅Ρ ΠΌΠ΅ΡΠΎΠ΄Ρ <c>Resolve</c> Π»ΠΈΠ±ΠΎ <c>Reject</c> Π΄Π»Ρ ΠΎΠΏΠΎΠ²Π΅ΡΠ΅Π½ΠΈΡ ΠΊΠ»ΠΈΠ΅ΡΠ½Π° ΠΎ | |
30 | /// Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΠΈ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ. |
|
30 | /// Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΠΈ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ. | |
31 | /// </para> |
|
31 | /// </para> | |
32 | /// <para> |
|
32 | /// <para> | |
33 | /// ΠΡΠ»ΠΈ ΡΠ΅ΡΠ²Π΅Ρ ΡΡΠΏΠ΅Π» Π²ΡΠΏΠΎΠ»Π½ΠΈΡΡ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅ Π΅ΡΠ΅ Π΄ΠΎ ΡΠΎΠ³ΠΎ, ΠΊΠ°ΠΊ ΠΊΠ»ΠΈΠ΅Π½Ρ Π½Π° Π½Π΅Π³ΠΎ ΠΏΠΎΠ΄ΠΏΠΈΡΠ°Π»ΡΡ, |
|
33 | /// ΠΡΠ»ΠΈ ΡΠ΅ΡΠ²Π΅Ρ ΡΡΠΏΠ΅Π» Π²ΡΠΏΠΎΠ»Π½ΠΈΡΡ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅ Π΅ΡΠ΅ Π΄ΠΎ ΡΠΎΠ³ΠΎ, ΠΊΠ°ΠΊ ΠΊΠ»ΠΈΠ΅Π½Ρ Π½Π° Π½Π΅Π³ΠΎ ΠΏΠΎΠ΄ΠΏΠΈΡΠ°Π»ΡΡ, | |
34 | /// ΡΠΎ Π² ΠΌΠΎΠΌΠ΅Π½Ρ ΠΏΠΎΠ΄ΠΏΠΈΡΠΊΠΈ ΠΊΠ»ΠΈΠ΅Π½ΡΠ° Π±ΡΠ΄ΡΡ Π²ΡΠ·Π²Π°Π½Ρ ΡΠΎΠΎΡΠ²Π΅ΡΡΠ²ΡΡΡΠΈΠ΅ ΡΠΎΠ±ΡΡΠΈΡ Π² ΡΠΈΠ½Ρ ΡΠΎΠ½Π½ΠΎΠΌ |
|
34 | /// ΡΠΎ Π² ΠΌΠΎΠΌΠ΅Π½Ρ ΠΏΠΎΠ΄ΠΏΠΈΡΠΊΠΈ ΠΊΠ»ΠΈΠ΅Π½ΡΠ° Π±ΡΠ΄ΡΡ Π²ΡΠ·Π²Π°Π½Ρ ΡΠΎΠΎΡΠ²Π΅ΡΡΠ²ΡΡΡΠΈΠ΅ ΡΠΎΠ±ΡΡΠΈΡ Π² ΡΠΈΠ½Ρ ΡΠΎΠ½Π½ΠΎΠΌ | |
35 | /// ΡΠ΅ΠΆΠΈΠΌΠ΅ ΠΈ ΠΊΠ»ΠΈΠ΅Π½Ρ Π±ΡΠ΄Π΅Ρ ΠΎΠΏΠΎΠ²Π΅ΡΠ΅Π½ Π² Π»ΡΠ±ΠΎΠΌ ΡΠ»ΡΡΠ°Π΅. ΠΠ½Π°ΡΠ΅, ΠΎΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊΠΈ Π΄ΠΎΠ±Π°Π²Π»ΡΡΡΡΡ Π² |
|
35 | /// ΡΠ΅ΠΆΠΈΠΌΠ΅ ΠΈ ΠΊΠ»ΠΈΠ΅Π½Ρ Π±ΡΠ΄Π΅Ρ ΠΎΠΏΠΎΠ²Π΅ΡΠ΅Π½ Π² Π»ΡΠ±ΠΎΠΌ ΡΠ»ΡΡΠ°Π΅. ΠΠ½Π°ΡΠ΅, ΠΎΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊΠΈ Π΄ΠΎΠ±Π°Π²Π»ΡΡΡΡΡ Π² | |
36 | /// ΡΠΏΠΈΡΠΎΠΊ Π² ΠΏΠΎΡΡΠ΄ΠΊΠ΅ ΠΏΠΎΠ΄ΠΏΠΈΡΠ°Π½ΠΈΡ ΠΈ Π² ΡΡΠΎΠΌ ΠΆΠ΅ ΠΏΠΎΡΡΠ΄ΠΊΠ΅ ΠΎΠ½ΠΈ Π±ΡΠ΄ΡΡ Π²ΡΠ·Π²Π°Π½Ρ ΠΏΡΠΈ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΠΈ |
|
36 | /// ΡΠΏΠΈΡΠΎΠΊ Π² ΠΏΠΎΡΡΠ΄ΠΊΠ΅ ΠΏΠΎΠ΄ΠΏΠΈΡΠ°Π½ΠΈΡ ΠΈ Π² ΡΡΠΎΠΌ ΠΆΠ΅ ΠΏΠΎΡΡΠ΄ΠΊΠ΅ ΠΎΠ½ΠΈ Π±ΡΠ΄ΡΡ Π²ΡΠ·Π²Π°Π½Ρ ΠΏΡΠΈ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΠΈ | |
37 | /// ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ. |
|
37 | /// ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ. | |
38 | /// </para> |
|
38 | /// </para> | |
39 | /// <para> |
|
39 | /// <para> | |
40 | /// ΠΠ±ΡΠ°Π±Π°ΡΡΠ²Π°Ρ ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΡ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ ΠΌΠΎΠΆΠ½ΠΎ ΠΏΡΠ΅ΠΎΠ±ΡΠ°Π·ΠΎΠ²ΡΠ²Π°ΡΡ ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΡ Π»ΠΈΠ±ΠΎ ΠΈΠ½ΠΈΡΠΈΠΈΡΠΎΠ²Π°ΡΡ |
|
40 | /// ΠΠ±ΡΠ°Π±Π°ΡΡΠ²Π°Ρ ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΡ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ ΠΌΠΎΠΆΠ½ΠΎ ΠΏΡΠ΅ΠΎΠ±ΡΠ°Π·ΠΎΠ²ΡΠ²Π°ΡΡ ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΡ Π»ΠΈΠ±ΠΎ ΠΈΠ½ΠΈΡΠΈΠΈΡΠΎΠ²Π°ΡΡ | |
41 | /// ΡΠ²ΡΠ·Π°Π½Π½ΡΠ΅ Π°ΡΠΈΠ½Ρ ΡΠΎΠ½Π½ΡΠ΅ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ, ΠΊΠΎΡΠΎΡΡΠ΅ ΡΠ°ΠΊΠΆΠ΅ Π²ΠΎΠ·Π²ΡΠ°ΡΠ°ΡΡ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ. ΠΠ»Ρ ΡΡΠΎΠ³ΠΎ ΡΠ»Π΅Π΄ΡΠ΅Ρ |
|
41 | /// ΡΠ²ΡΠ·Π°Π½Π½ΡΠ΅ Π°ΡΠΈΠ½Ρ ΡΠΎΠ½Π½ΡΠ΅ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ, ΠΊΠΎΡΠΎΡΡΠ΅ ΡΠ°ΠΊΠΆΠ΅ Π²ΠΎΠ·Π²ΡΠ°ΡΠ°ΡΡ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ. ΠΠ»Ρ ΡΡΠΎΠ³ΠΎ ΡΠ»Π΅Π΄ΡΠ΅Ρ | |
42 | /// ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΡ ΡΠΎΠΎΡΠ²Π΅ΡΡΡΠ²ΡΡΡΡΡ ΡΠΎΡΠΌΡ ΠΌΠ΅ΡΠΎΠ΄Π΅ <c>Then</c>. |
|
42 | /// ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΡ ΡΠΎΠΎΡΠ²Π΅ΡΡΡΠ²ΡΡΡΡΡ ΡΠΎΡΠΌΡ ΠΌΠ΅ΡΠΎΠ΄Π΅ <c>Then</c>. | |
43 | /// </para> |
|
43 | /// </para> | |
44 | /// <para> |
|
44 | /// <para> | |
45 | /// Π’Π°ΠΊΠΆΠ΅ Ρ ΠΎΡΠΎΡΠΈΠΌ ΠΏΡΠ°Π²ΠΈΠ»ΠΎΠΌ ΡΠ²Π»ΡΠ΅ΡΡΡ ΡΠΎ, ΡΡΠΎ <c>Resolve</c> ΠΈ <c>Reject</c> Π΄ΠΎΠ»ΠΆΠ΅Π½ Π²ΡΠ·ΡΠ²Π°ΡΡ |
|
45 | /// Π’Π°ΠΊΠΆΠ΅ Ρ ΠΎΡΠΎΡΠΈΠΌ ΠΏΡΠ°Π²ΠΈΠ»ΠΎΠΌ ΡΠ²Π»ΡΠ΅ΡΡΡ ΡΠΎ, ΡΡΠΎ <c>Resolve</c> ΠΈ <c>Reject</c> Π΄ΠΎΠ»ΠΆΠ΅Π½ Π²ΡΠ·ΡΠ²Π°ΡΡ | |
46 | /// ΡΠΎΠ»ΡΠΊΠΎ ΠΈΠ½ΠΈΡΠΈΠ°ΡΠΎΡ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ ΠΈΠ½Π°ΡΠ΅ ΠΌΠΎΠ³ΡΡ Π²ΠΎΠ·Π½ΠΈΠΊΠ½ΡΡΡ ΠΏΡΠΎΡΠΈΠ²ΠΎΡΠ΅ΡΠΈΡ. |
|
46 | /// ΡΠΎΠ»ΡΠΊΠΎ ΠΈΠ½ΠΈΡΠΈΠ°ΡΠΎΡ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ ΠΈΠ½Π°ΡΠ΅ ΠΌΠΎΠ³ΡΡ Π²ΠΎΠ·Π½ΠΈΠΊΠ½ΡΡΡ ΠΏΡΠΎΡΠΈΠ²ΠΎΡΠ΅ΡΠΈΡ. | |
47 | /// </para> |
|
47 | /// </para> | |
48 | /// </remarks> |
|
48 | /// </remarks> | |
49 | public class Promise<T> : IPromise<T> { |
|
49 | public class Promise<T> : IPromise<T> { | |
50 |
|
50 | |||
51 | protected struct HandlerDescriptor { |
|
51 | protected struct HandlerDescriptor { | |
52 | public ResultHandler<T> resultHandler; |
|
52 | public ResultHandler<T> resultHandler; | |
53 | public ErrorHandler<T> errorHandler; |
|
53 | public ErrorHandler<T> errorHandler; | |
54 | public Action cancellHandler; |
|
54 | public Action cancellHandler; | |
55 | public Promise<T> medium; |
|
55 | public Promise<T> medium; | |
56 |
|
56 | |||
57 | public void Resolve(T result) { |
|
57 | public void Resolve(T result) { | |
58 | if (resultHandler != null) { |
|
58 | if (resultHandler != null) { | |
59 | try { |
|
59 | try { | |
60 | resultHandler(result); |
|
60 | resultHandler(result); | |
61 | } catch (Exception e) { |
|
61 | } catch (Exception e) { | |
62 | Reject(e); |
|
62 | Reject(e); | |
63 | return; |
|
63 | return; | |
64 | } |
|
64 | } | |
65 | } |
|
65 | } | |
66 | if (medium != null) |
|
66 | if (medium != null) | |
67 | medium.Resolve(result); |
|
67 | medium.Resolve(result); | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | public void Reject(Exception err) { |
|
70 | public void Reject(Exception err) { | |
71 | if (errorHandler != null) { |
|
71 | if (errorHandler != null) { | |
72 | try { |
|
72 | try { | |
73 | var res = errorHandler(err); |
|
73 | var res = errorHandler(err); | |
74 | if (medium != null) |
|
74 | if (medium != null) | |
75 | medium.Resolve(res); |
|
75 | medium.Resolve(res); | |
76 | } catch (TransientPromiseException err2) { |
|
76 | /*} catch (TransientPromiseException err2) { | |
77 | if (medium != null) |
|
77 | if (medium != null) | |
78 |
|
|
78 | medium.Reject(err2.InnerException);*/ | |
79 | } catch (Exception err2) { |
|
79 | } catch (Exception err2) { | |
80 | if (medium != null) |
|
80 | if (medium != null) | |
81 | medium.Reject(err2); |
|
81 | medium.Reject(err2); | |
82 | } |
|
82 | } | |
83 | } else if (medium != null) |
|
83 | } else if (medium != null) | |
84 | medium.Reject(err); |
|
84 | medium.Reject(err); | |
85 | } |
|
85 | } | |
86 |
|
86 | |||
87 | public void Cancel() { |
|
87 | public void Cancel() { | |
88 | if (cancellHandler != null) { |
|
88 | if (cancellHandler != null) { | |
89 | try { |
|
89 | try { | |
90 | cancellHandler(); |
|
90 | cancellHandler(); | |
91 | } catch (Exception err) { |
|
91 | } catch (Exception err) { | |
92 | Reject(err); |
|
92 | Reject(err); | |
93 | return; |
|
93 | return; | |
94 | } |
|
94 | } | |
95 | } |
|
95 | } | |
96 | if (medium != null) |
|
96 | if (medium != null) | |
97 | medium.Cancel(); |
|
97 | medium.Cancel(); | |
98 | } |
|
98 | } | |
99 | } |
|
99 | } | |
100 |
|
100 | |||
101 | const int UNRESOLVED_SATE = 0; |
|
101 | const int UNRESOLVED_SATE = 0; | |
102 | const int TRANSITIONAL_STATE = 1; |
|
102 | const int TRANSITIONAL_STATE = 1; | |
103 | const int SUCCEEDED_STATE = 2; |
|
103 | const int SUCCEEDED_STATE = 2; | |
104 | const int REJECTED_STATE = 3; |
|
104 | const int REJECTED_STATE = 3; | |
105 | const int CANCELLED_STATE = 4; |
|
105 | const int CANCELLED_STATE = 4; | |
106 |
|
106 | |||
107 | readonly bool m_cancellable; |
|
107 | readonly bool m_cancellable; | |
108 |
|
108 | |||
109 | int m_childrenCount = 0; |
|
109 | int m_childrenCount = 0; | |
110 | int m_state; |
|
110 | int m_state; | |
111 | T m_result; |
|
111 | T m_result; | |
112 | Exception m_error; |
|
112 | Exception m_error; | |
113 |
|
113 | |||
114 | readonly MTQueue<HandlerDescriptor> m_handlers = new MTQueue<HandlerDescriptor>(); |
|
114 | readonly MTQueue<HandlerDescriptor> m_handlers = new MTQueue<HandlerDescriptor>(); | |
115 |
|
115 | |||
116 | public Promise() { |
|
116 | public Promise() { | |
117 | m_cancellable = true; |
|
117 | m_cancellable = true; | |
118 | } |
|
118 | } | |
119 |
|
119 | |||
120 | public Promise(IPromise parent, bool cancellable) { |
|
120 | public Promise(IPromise parent, bool cancellable) { | |
121 | m_cancellable = cancellable; |
|
121 | m_cancellable = cancellable; | |
122 | if (parent != null) |
|
122 | if (parent != null) | |
123 | AddHandler( |
|
123 | AddHandler( | |
124 | null, |
|
124 | null, | |
125 | null, |
|
125 | null, | |
126 | () => { |
|
126 | () => { | |
127 | if (parent.IsExclusive) |
|
127 | if (parent.IsExclusive) | |
128 | parent.Cancel(); |
|
128 | parent.Cancel(); | |
129 | }, |
|
129 | }, | |
130 | null |
|
130 | null | |
131 | ); |
|
131 | ); | |
132 | } |
|
132 | } | |
133 |
|
133 | |||
134 | bool BeginTransit() { |
|
134 | bool BeginTransit() { | |
135 | return UNRESOLVED_SATE == Interlocked.CompareExchange(ref m_state, TRANSITIONAL_STATE, UNRESOLVED_SATE); |
|
135 | return UNRESOLVED_SATE == Interlocked.CompareExchange(ref m_state, TRANSITIONAL_STATE, UNRESOLVED_SATE); | |
136 | } |
|
136 | } | |
137 |
|
137 | |||
138 | void CompleteTransit(int state) { |
|
138 | void CompleteTransit(int state) { | |
139 | if (TRANSITIONAL_STATE != Interlocked.CompareExchange(ref m_state, state, TRANSITIONAL_STATE)) |
|
139 | if (TRANSITIONAL_STATE != Interlocked.CompareExchange(ref m_state, state, TRANSITIONAL_STATE)) | |
140 | throw new InvalidOperationException("Can't complete transition when the object isn't in the transitional state"); |
|
140 | throw new InvalidOperationException("Can't complete transition when the object isn't in the transitional state"); | |
141 | } |
|
141 | } | |
142 |
|
142 | |||
143 | void WaitTransition() { |
|
143 | void WaitTransition() { | |
144 | while (m_state == TRANSITIONAL_STATE) { |
|
144 | while (m_state == TRANSITIONAL_STATE) { | |
145 | Thread.MemoryBarrier(); |
|
145 | Thread.MemoryBarrier(); | |
146 | } |
|
146 | } | |
147 | } |
|
147 | } | |
148 |
|
148 | |||
149 | public bool IsResolved { |
|
149 | public bool IsResolved { | |
150 | get { |
|
150 | get { | |
151 | Thread.MemoryBarrier(); |
|
151 | Thread.MemoryBarrier(); | |
152 | return m_state > 1; |
|
152 | return m_state > 1; | |
153 | } |
|
153 | } | |
154 | } |
|
154 | } | |
155 |
|
155 | |||
156 | public bool IsCancelled { |
|
156 | public bool IsCancelled { | |
157 | get { |
|
157 | get { | |
158 | Thread.MemoryBarrier(); |
|
158 | Thread.MemoryBarrier(); | |
159 | return m_state == CANCELLED_STATE; |
|
159 | return m_state == CANCELLED_STATE; | |
160 | } |
|
160 | } | |
161 | } |
|
161 | } | |
162 |
|
162 | |||
163 | public Type PromiseType { |
|
163 | public Type PromiseType { | |
164 | get { return typeof(T); } |
|
164 | get { return typeof(T); } | |
165 | } |
|
165 | } | |
166 |
|
166 | |||
167 | /// <summary> |
|
167 | /// <summary> | |
168 | /// ΠΡΠΏΠΎΠ»Π½ΡΠ΅Ρ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅, ΡΠΎΠΎΠ±ΡΠ°Ρ ΠΎΠ± ΡΡΠΏΠ΅ΡΠ½ΠΎΠΌ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΠΈ. |
|
168 | /// ΠΡΠΏΠΎΠ»Π½ΡΠ΅Ρ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅, ΡΠΎΠΎΠ±ΡΠ°Ρ ΠΎΠ± ΡΡΠΏΠ΅ΡΠ½ΠΎΠΌ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΠΈ. | |
169 | /// </summary> |
|
169 | /// </summary> | |
170 | /// <param name="result">Π Π΅Π·ΡΠ»ΡΡΠ°Ρ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΡ.</param> |
|
170 | /// <param name="result">Π Π΅Π·ΡΠ»ΡΡΠ°Ρ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΡ.</param> | |
171 | /// <exception cref="InvalidOperationException">ΠΠ°Π½Π½ΠΎΠ΅ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅ ΡΠΆΠ΅ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΎ</exception> |
|
171 | /// <exception cref="InvalidOperationException">ΠΠ°Π½Π½ΠΎΠ΅ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅ ΡΠΆΠ΅ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΎ</exception> | |
172 | public void Resolve(T result) { |
|
172 | public void Resolve(T result) { | |
173 | if (BeginTransit()) { |
|
173 | if (BeginTransit()) { | |
174 | m_result = result; |
|
174 | m_result = result; | |
175 | CompleteTransit(SUCCEEDED_STATE); |
|
175 | CompleteTransit(SUCCEEDED_STATE); | |
176 | OnStateChanged(); |
|
176 | OnStateChanged(); | |
177 | } else { |
|
177 | } else { | |
178 | WaitTransition(); |
|
178 | WaitTransition(); | |
179 | if (m_state != CANCELLED_STATE) |
|
179 | if (m_state != CANCELLED_STATE) | |
180 | throw new InvalidOperationException("The promise is already resolved"); |
|
180 | throw new InvalidOperationException("The promise is already resolved"); | |
181 | } |
|
181 | } | |
182 | } |
|
182 | } | |
183 |
|
183 | |||
184 | /// <summary> |
|
184 | /// <summary> | |
185 | /// ΠΡΠΏΠΎΠ»Π½ΡΠ΅Ρ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅, ΡΠΎΠΎΠ±ΡΠ°Ρ ΠΎΠ± ΡΡΠΏΠ΅ΡΠ½ΠΎΠΌ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΠΈ. Π Π΅Π·ΡΠ»ΡΡΠ°ΡΠΎΠΌ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΡ Π±ΡΠ΄Π΅Ρ ΠΏΡΡΡΠΎΠ΅ Π·Π½Π°ΡΠ΅Π½ΠΈΡ. |
|
185 | /// ΠΡΠΏΠΎΠ»Π½ΡΠ΅Ρ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅, ΡΠΎΠΎΠ±ΡΠ°Ρ ΠΎΠ± ΡΡΠΏΠ΅ΡΠ½ΠΎΠΌ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΠΈ. Π Π΅Π·ΡΠ»ΡΡΠ°ΡΠΎΠΌ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΡ Π±ΡΠ΄Π΅Ρ ΠΏΡΡΡΠΎΠ΅ Π·Π½Π°ΡΠ΅Π½ΠΈΡ. | |
186 | /// </summary> |
|
186 | /// </summary> | |
187 | /// <remarks> |
|
187 | /// <remarks> | |
188 | /// ΠΠ°Π½Π½ΡΠΉ Π²Π°ΡΠΈΠ°Π½Ρ ΡΠ΄ΠΎΠ±Π΅Π½ Π² ΡΠ»ΡΡΠ°ΡΡ , ΠΊΠΎΠ³Π΄Π° ΠΈΠ½ΡΠ΅ΡΠ΅ΡΠ΅Π½ ΡΠ°ΠΊΡ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΡ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ, Π½Π΅ΠΆΠ΅Π»ΠΈ ΠΏΠΎΠ»ΡΡΠ΅Π½Π½ΠΎΠ΅ Π·Π½Π°ΡΠ΅Π½ΠΈΠ΅. |
|
188 | /// ΠΠ°Π½Π½ΡΠΉ Π²Π°ΡΠΈΠ°Π½Ρ ΡΠ΄ΠΎΠ±Π΅Π½ Π² ΡΠ»ΡΡΠ°ΡΡ , ΠΊΠΎΠ³Π΄Π° ΠΈΠ½ΡΠ΅ΡΠ΅ΡΠ΅Π½ ΡΠ°ΠΊΡ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΡ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ, Π½Π΅ΠΆΠ΅Π»ΠΈ ΠΏΠΎΠ»ΡΡΠ΅Π½Π½ΠΎΠ΅ Π·Π½Π°ΡΠ΅Π½ΠΈΠ΅. | |
189 | /// </remarks> |
|
189 | /// </remarks> | |
190 | public void Resolve() { |
|
190 | public void Resolve() { | |
191 | Resolve(default(T)); |
|
191 | Resolve(default(T)); | |
192 | } |
|
192 | } | |
193 |
|
193 | |||
194 | /// <summary> |
|
194 | /// <summary> | |
195 | /// ΠΡΠΏΠΎΠ»Π½ΡΠ΅Ρ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅, ΡΠΎΠΎΠ±ΡΠ°Ρ ΠΎΠ± ΠΎΡΠΈΠ±ΠΊΠ΅ |
|
195 | /// ΠΡΠΏΠΎΠ»Π½ΡΠ΅Ρ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅, ΡΠΎΠΎΠ±ΡΠ°Ρ ΠΎΠ± ΠΎΡΠΈΠ±ΠΊΠ΅ | |
196 | /// </summary> |
|
196 | /// </summary> | |
197 | /// <remarks> |
|
197 | /// <remarks> | |
198 | /// ΠΠΎΡΠΊΠΎΠ»ΡΠΊΡ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅ Π΄ΠΎΠ»ΠΆΠ½ΠΎ ΡΠ°Π±ΠΎΡΠ°ΡΡ Π² ΠΌΠ½ΠΎΠ³ΠΎΠΏΡΠΎΡΠ½ΠΎΠΉ ΡΡΠ΅Π΄Π΅, ΠΏΡΠΈ Π΅Π³ΠΎ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΠΈ ΡΡΠ°Π·Ρ Π½Π΅ΡΠΊΠΎΠ»ΡΠΊΠΎ ΠΏΠΎΡΠΎΠΊΠΎΠ² |
|
198 | /// ΠΠΎΡΠΊΠΎΠ»ΡΠΊΡ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅ Π΄ΠΎΠ»ΠΆΠ½ΠΎ ΡΠ°Π±ΠΎΡΠ°ΡΡ Π² ΠΌΠ½ΠΎΠ³ΠΎΠΏΡΠΎΡΠ½ΠΎΠΉ ΡΡΠ΅Π΄Π΅, ΠΏΡΠΈ Π΅Π³ΠΎ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΠΈ ΡΡΠ°Π·Ρ Π½Π΅ΡΠΊΠΎΠ»ΡΠΊΠΎ ΠΏΠΎΡΠΎΠΊΠΎΠ² | |
199 | /// ΠΌΠΎΠ³Ρ Π²Π΅ΡΠ½ΡΡΡ ΠΎΡΠΈΠ±ΠΊΡ, ΠΏΡΠΈ ΡΡΠΎΠΌ ΡΠΎΠ»ΡΠΊΠΎ ΠΏΠ΅ΡΠ²Π°Ρ Π±ΡΠ΄Π΅Ρ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½Π° Π² ΠΊΠ°ΡΠ΅ΡΡΠ²Π΅ ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΠ°, ΠΎΡΡΠ°Π»ΡΠ½ΡΠ΅ |
|
199 | /// ΠΌΠΎΠ³Ρ Π²Π΅ΡΠ½ΡΡΡ ΠΎΡΠΈΠ±ΠΊΡ, ΠΏΡΠΈ ΡΡΠΎΠΌ ΡΠΎΠ»ΡΠΊΠΎ ΠΏΠ΅ΡΠ²Π°Ρ Π±ΡΠ΄Π΅Ρ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½Π° Π² ΠΊΠ°ΡΠ΅ΡΡΠ²Π΅ ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΠ°, ΠΎΡΡΠ°Π»ΡΠ½ΡΠ΅ | |
200 | /// Π±ΡΠ΄ΡΡ ΠΏΡΠΎΠΈΠ³Π½ΠΎΡΠΈΡΠΎΠ²Π°Π½Ρ. |
|
200 | /// Π±ΡΠ΄ΡΡ ΠΏΡΠΎΠΈΠ³Π½ΠΎΡΠΈΡΠΎΠ²Π°Π½Ρ. | |
201 | /// </remarks> |
|
201 | /// </remarks> | |
202 | /// <param name="error">ΠΡΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅ Π²ΠΎΠ·Π½ΠΈΠΊΡΠ΅Π΅ ΠΏΡΠΈ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΠΈ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ</param> |
|
202 | /// <param name="error">ΠΡΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅ Π²ΠΎΠ·Π½ΠΈΠΊΡΠ΅Π΅ ΠΏΡΠΈ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΠΈ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ</param> | |
203 | /// <exception cref="InvalidOperationException">ΠΠ°Π½Π½ΠΎΠ΅ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅ ΡΠΆΠ΅ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΎ</exception> |
|
203 | /// <exception cref="InvalidOperationException">ΠΠ°Π½Π½ΠΎΠ΅ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅ ΡΠΆΠ΅ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΎ</exception> | |
204 | public void Reject(Exception error) { |
|
204 | public void Reject(Exception error) { | |
205 | if (BeginTransit()) { |
|
205 | if (BeginTransit()) { | |
206 | m_error = error; |
|
206 | m_error = error is TransientPromiseException ? error.InnerException : error; | |
207 | CompleteTransit(REJECTED_STATE); |
|
207 | CompleteTransit(REJECTED_STATE); | |
208 | OnStateChanged(); |
|
208 | OnStateChanged(); | |
209 | } else { |
|
209 | } else { | |
210 | WaitTransition(); |
|
210 | WaitTransition(); | |
211 | if (m_state == SUCCEEDED_STATE) |
|
211 | if (m_state == SUCCEEDED_STATE) | |
212 | throw new InvalidOperationException("The promise is already resolved"); |
|
212 | throw new InvalidOperationException("The promise is already resolved"); | |
213 | } |
|
213 | } | |
214 | } |
|
214 | } | |
215 |
|
215 | |||
216 | /// <summary> |
|
216 | /// <summary> | |
217 | /// ΠΡΠΌΠ΅Π½ΡΠ΅Ρ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΡ, Π΅ΡΠ»ΠΈ ΡΡΠΎ Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎ. |
|
217 | /// ΠΡΠΌΠ΅Π½ΡΠ΅Ρ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΡ, Π΅ΡΠ»ΠΈ ΡΡΠΎ Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎ. | |
218 | /// </summary> |
|
218 | /// </summary> | |
219 | /// <remarks>ΠΠ»Ρ ΠΎΠΏΡΠ΅Π΄Π΅Π»Π΅Π½ΠΈΡ Π±ΡΠ»Π° Π»ΠΈ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΡ ΠΎΡΠΌΠ΅Π½Π΅Π½Π° ΡΠ»Π΅Π΄ΡΠ΅Ρ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΡ ΡΠ²ΠΎΠΉΡΡΠ²ΠΎ <see cref="IsCancelled"/>.</remarks> |
|
219 | /// <remarks>ΠΠ»Ρ ΠΎΠΏΡΠ΅Π΄Π΅Π»Π΅Π½ΠΈΡ Π±ΡΠ»Π° Π»ΠΈ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΡ ΠΎΡΠΌΠ΅Π½Π΅Π½Π° ΡΠ»Π΅Π΄ΡΠ΅Ρ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΡ ΡΠ²ΠΎΠΉΡΡΠ²ΠΎ <see cref="IsCancelled"/>.</remarks> | |
220 | public void Cancel() { |
|
220 | public void Cancel() { | |
221 | if (m_cancellable && BeginTransit()) { |
|
221 | if (m_cancellable && BeginTransit()) { | |
222 | CompleteTransit(CANCELLED_STATE); |
|
222 | CompleteTransit(CANCELLED_STATE); | |
223 | OnStateChanged(); |
|
223 | OnStateChanged(); | |
224 | } |
|
224 | } | |
225 | } |
|
225 | } | |
226 |
|
226 | |||
227 | public IPromise<T> Then(ResultHandler<T> success, ErrorHandler<T> error, Action cancel) { |
|
227 | public IPromise<T> Then(ResultHandler<T> success, ErrorHandler<T> error, Action cancel) { | |
228 | if (success == null && error == null && cancel == null) |
|
228 | if (success == null && error == null && cancel == null) | |
229 | return this; |
|
229 | return this; | |
230 |
|
230 | |||
231 | var medium = new Promise<T>(this, true); |
|
231 | var medium = new Promise<T>(this, true); | |
232 |
|
232 | |||
233 | AddHandler(success, error, cancel, medium); |
|
233 | AddHandler(success, error, cancel, medium); | |
234 |
|
234 | |||
235 | return medium; |
|
235 | return medium; | |
236 | } |
|
236 | } | |
237 |
|
237 | |||
238 | /// <summary> |
|
238 | /// <summary> | |
239 | /// Adds new handlers to this promise. |
|
239 | /// Adds new handlers to this promise. | |
240 | /// </summary> |
|
240 | /// </summary> | |
241 | /// <param name="success">The handler of the successfully completed operation. |
|
241 | /// <param name="success">The handler of the successfully completed operation. | |
242 | /// This handler will recieve an operation result as a parameter.</param> |
|
242 | /// This handler will recieve an operation result as a parameter.</param> | |
243 | /// <param name="error">Handles an exception that may occur during the operation and returns the value which will be used as the result of the operation.</param> |
|
243 | /// <param name="error">Handles an exception that may occur during the operation and returns the value which will be used as the result of the operation.</param> | |
244 | /// <returns>The new promise chained to this one.</returns> |
|
244 | /// <returns>The new promise chained to this one.</returns> | |
245 | public IPromise<T> Then(ResultHandler<T> success, ErrorHandler<T> error) { |
|
245 | public IPromise<T> Then(ResultHandler<T> success, ErrorHandler<T> error) { | |
246 | if (success == null && error == null) |
|
246 | if (success == null && error == null) | |
247 | return this; |
|
247 | return this; | |
248 |
|
248 | |||
249 | var medium = new Promise<T>(this, true); |
|
249 | var medium = new Promise<T>(this, true); | |
250 |
|
250 | |||
251 | AddHandler(success, error, null, medium); |
|
251 | AddHandler(success, error, null, medium); | |
252 |
|
252 | |||
253 | return medium; |
|
253 | return medium; | |
254 | } |
|
254 | } | |
255 |
|
255 | |||
256 |
|
256 | |||
257 |
|
257 | |||
258 |
|
258 | |||
259 | public IPromise<T> Then(ResultHandler<T> success) { |
|
259 | public IPromise<T> Then(ResultHandler<T> success) { | |
260 | if (success == null) |
|
260 | if (success == null) | |
261 | return this; |
|
261 | return this; | |
262 |
|
262 | |||
263 | var medium = new Promise<T>(this, true); |
|
263 | var medium = new Promise<T>(this, true); | |
264 |
|
264 | |||
265 | AddHandler(success, null, null, medium); |
|
265 | AddHandler(success, null, null, medium); | |
266 |
|
266 | |||
267 | return medium; |
|
267 | return medium; | |
268 | } |
|
268 | } | |
269 |
|
269 | |||
270 | /// <summary> |
|
270 | /// <summary> | |
271 | /// ΠΠΎΡΠ»Π΅Π΄Π½ΠΈΠΉ ΠΎΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊ Π² ΡΠ΅ΠΏΠΎΡΠΊΠΈ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠΉ. |
|
271 | /// ΠΠΎΡΠ»Π΅Π΄Π½ΠΈΠΉ ΠΎΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊ Π² ΡΠ΅ΠΏΠΎΡΠΊΠΈ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠΉ. | |
272 | /// </summary> |
|
272 | /// </summary> | |
273 | /// <param name="success"></param> |
|
273 | /// <param name="success"></param> | |
274 | /// <param name="error"></param> |
|
274 | /// <param name="error"></param> | |
275 | /// <param name="cancel"></param> |
|
275 | /// <param name="cancel"></param> | |
276 | /// <remarks> |
|
276 | /// <remarks> | |
277 | /// <para> |
|
277 | /// <para> | |
278 | /// ΠΠ°Π½Π½ΡΠΉ ΠΌΠ΅ΡΠΎΠ΄ Π½Π΅ ΡΠΎΠ·Π΄Π°Π΅Ρ ΡΠ²ΡΠ·Π°Π½Π½ΠΎΠ³ΠΎ Ρ ΡΠ΅ΠΊΡΡΠΈΠΌ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ ΠΈ ΠΏΡΠ΅Π΄Π½Π°Π·Π½Π°ΡΠ΅Π½ Π΄Π»Ρ ΠΎΠΊΠΎΠ½ΡΠ°Π½ΠΈΡ |
|
278 | /// ΠΠ°Π½Π½ΡΠΉ ΠΌΠ΅ΡΠΎΠ΄ Π½Π΅ ΡΠΎΠ·Π΄Π°Π΅Ρ ΡΠ²ΡΠ·Π°Π½Π½ΠΎΠ³ΠΎ Ρ ΡΠ΅ΠΊΡΡΠΈΠΌ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ ΠΈ ΠΏΡΠ΅Π΄Π½Π°Π·Π½Π°ΡΠ΅Π½ Π΄Π»Ρ ΠΎΠΊΠΎΠ½ΡΠ°Π½ΠΈΡ | |
279 | /// ΡΡΠΈΠ½Ρ ΡΠΎΠ½Π½ΠΎΠΉ ΡΠ΅ΠΏΠΎΡΠΊΠΈ. |
|
279 | /// ΡΡΠΈΠ½Ρ ΡΠΎΠ½Π½ΠΎΠΉ ΡΠ΅ΠΏΠΎΡΠΊΠΈ. | |
280 | /// </para> |
|
280 | /// </para> | |
281 | /// <para> |
|
281 | /// <para> | |
282 | /// ΠΡΠ»ΠΈ Π΄Π°Π½Π½ΡΠΉ ΠΌΠ΅ΡΠΎΠ΄ Π²ΡΠ·Π²Π°ΡΡ Π½Π΅ΡΠΊΠΎΠ»ΡΠΊΠΎ ΡΠ°Π·, Π»ΠΈΠ±ΠΎ Π΄ΠΎΠ±Π°Π²ΠΈΡΡ Π΄ΡΡΠ³ΠΈΠ΅ ΠΎΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊΠΈ, ΡΠΎ ΡΠ΅ΠΏΠΎΡΠΊΠ° |
|
282 | /// ΠΡΠ»ΠΈ Π΄Π°Π½Π½ΡΠΉ ΠΌΠ΅ΡΠΎΠ΄ Π²ΡΠ·Π²Π°ΡΡ Π½Π΅ΡΠΊΠΎΠ»ΡΠΊΠΎ ΡΠ°Π·, Π»ΠΈΠ±ΠΎ Π΄ΠΎΠ±Π°Π²ΠΈΡΡ Π΄ΡΡΠ³ΠΈΠ΅ ΠΎΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊΠΈ, ΡΠΎ ΡΠ΅ΠΏΠΎΡΠΊΠ° | |
283 | /// Π½Π΅ Π±ΡΠ΄Π΅Ρ ΠΎΠ΄ΠΈΠ½ΠΎΡΠ½ΠΎΠΉ <see cref="IsExclusive"/> ΠΈ, ΠΊΠ°ΠΊ ΡΠ»Π΅Π΄ΡΡΠ²ΠΈΠ΅, Π±ΡΠ΄Π΅Ρ Π½Π΅Π²ΠΎΠ·ΠΌΠΎΠΆΠ½Π° ΠΎΡΠΌΠ΅Π½Π° |
|
283 | /// Π½Π΅ Π±ΡΠ΄Π΅Ρ ΠΎΠ΄ΠΈΠ½ΠΎΡΠ½ΠΎΠΉ <see cref="IsExclusive"/> ΠΈ, ΠΊΠ°ΠΊ ΡΠ»Π΅Π΄ΡΡΠ²ΠΈΠ΅, Π±ΡΠ΄Π΅Ρ Π½Π΅Π²ΠΎΠ·ΠΌΠΎΠΆΠ½Π° ΠΎΡΠΌΠ΅Π½Π° | |
284 | /// Π²ΡΠ΅ΠΉ ΡΠ΅ΠΏΠΈ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠΉ ΡΠ½ΠΈΠ·Ρ (Ρ ΡΠ°ΠΌΠΎΠ³ΠΎ ΠΏΠΎΡΠ»Π΅Π΄Π½Π΅Π³ΠΎ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ). |
|
284 | /// Π²ΡΠ΅ΠΉ ΡΠ΅ΠΏΠΈ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠΉ ΡΠ½ΠΈΠ·Ρ (Ρ ΡΠ°ΠΌΠΎΠ³ΠΎ ΠΏΠΎΡΠ»Π΅Π΄Π½Π΅Π³ΠΎ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ). | |
285 | /// </para> |
|
285 | /// </para> | |
286 | /// </remarks> |
|
286 | /// </remarks> | |
287 | public void Last(ResultHandler<T> success, ErrorHandler error, Action cancel) { |
|
287 | public void Last(ResultHandler<T> success, ErrorHandler error, Action cancel) { | |
288 | if (success == null && error == null && cancel == null) |
|
288 | if (success == null && error == null && cancel == null) | |
289 | return; |
|
289 | return; | |
290 |
|
290 | |||
291 | ErrorHandler<T> errorHandler = null; |
|
291 | ErrorHandler<T> errorHandler = null; | |
292 | if (error != null) |
|
292 | if (error != null) | |
293 | errorHandler = err => { |
|
293 | errorHandler = err => { | |
294 | error(err); |
|
294 | error(err); | |
295 | return default(T); |
|
295 | return default(T); | |
296 | }; |
|
296 | }; | |
297 | AddHandler(success, errorHandler, cancel, null); |
|
297 | AddHandler(success, errorHandler, cancel, null); | |
298 | } |
|
298 | } | |
299 |
|
299 | |||
300 | public void Last(ResultHandler<T> success, ErrorHandler error) { |
|
300 | public void Last(ResultHandler<T> success, ErrorHandler error) { | |
301 | Last(success, error, null); |
|
301 | Last(success, error, null); | |
302 | } |
|
302 | } | |
303 |
|
303 | |||
304 | public void Last(ResultHandler<T> success) { |
|
304 | public void Last(ResultHandler<T> success) { | |
305 | Last(success, null, null); |
|
305 | Last(success, null, null); | |
306 | } |
|
306 | } | |
307 |
|
307 | |||
308 | public IPromise Error(ErrorHandler error) { |
|
308 | public IPromise Error(ErrorHandler error) { | |
309 | if (error == null) |
|
309 | if (error == null) | |
310 | return this; |
|
310 | return this; | |
311 |
|
311 | |||
312 | var medium = new Promise<T>(this, true); |
|
312 | var medium = new Promise<T>(this, true); | |
313 |
|
313 | |||
314 | AddHandler( |
|
314 | AddHandler( | |
315 | null, |
|
315 | null, | |
316 | e => { |
|
316 | e => { | |
317 | error(e); |
|
317 | error(e); | |
318 | return default(T); |
|
318 | return default(T); | |
319 | }, |
|
319 | }, | |
320 | null, |
|
320 | null, | |
321 | medium |
|
321 | medium | |
322 | ); |
|
322 | ); | |
323 |
|
323 | |||
324 | return medium; |
|
324 | return medium; | |
325 | } |
|
325 | } | |
326 |
|
326 | |||
327 | /// <summary> |
|
327 | /// <summary> | |
328 | /// Handles error and allows to keep the promise. |
|
328 | /// Handles error and allows to keep the promise. | |
329 | /// </summary> |
|
329 | /// </summary> | |
330 | /// <remarks> |
|
330 | /// <remarks> | |
331 | /// If the specified handler throws an exception, this exception will be used to reject the promise. |
|
331 | /// If the specified handler throws an exception, this exception will be used to reject the promise. | |
332 | /// </remarks> |
|
332 | /// </remarks> | |
333 | /// <param name="handler">The error handler which returns the result of the promise.</param> |
|
333 | /// <param name="handler">The error handler which returns the result of the promise.</param> | |
334 | /// <returns>New promise.</returns> |
|
334 | /// <returns>New promise.</returns> | |
335 | public IPromise<T> Error(ErrorHandler<T> handler) { |
|
335 | public IPromise<T> Error(ErrorHandler<T> handler) { | |
336 | if (handler == null) |
|
336 | if (handler == null) | |
337 | return this; |
|
337 | return this; | |
338 |
|
338 | |||
339 | var medium = new Promise<T>(this, true); |
|
339 | var medium = new Promise<T>(this, true); | |
340 |
|
340 | |||
341 | AddHandler(null, handler, null, medium); |
|
341 | AddHandler(null, handler, null, medium); | |
342 |
|
342 | |||
343 | return medium; |
|
343 | return medium; | |
344 | } |
|
344 | } | |
345 |
|
345 | |||
346 | /// <summary> |
|
346 | /// <summary> | |
347 | /// ΠΠΎΠ·Π²ΠΎΠ»ΡΠ΅Ρ ΠΏΡΠ΅ΠΎΠ±ΡΠ°Π·ΠΎΠ²Π°ΡΡ ΡΠ΅Π·ΡΠ»ΡΡΠ°Ρ Π²ΡΠΏΠΎΠ»Π΅Π½ΠΈΡ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ ΠΊ Π½ΠΎΠ²ΠΎΠΌΡ ΡΠΈΠΏΡ. |
|
347 | /// ΠΠΎΠ·Π²ΠΎΠ»ΡΠ΅Ρ ΠΏΡΠ΅ΠΎΠ±ΡΠ°Π·ΠΎΠ²Π°ΡΡ ΡΠ΅Π·ΡΠ»ΡΡΠ°Ρ Π²ΡΠΏΠΎΠ»Π΅Π½ΠΈΡ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ ΠΊ Π½ΠΎΠ²ΠΎΠΌΡ ΡΠΈΠΏΡ. | |
348 | /// </summary> |
|
348 | /// </summary> | |
349 | /// <typeparam name="TNew">ΠΠΎΠ²ΡΠΉ ΡΠΈΠΏ ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΠ°.</typeparam> |
|
349 | /// <typeparam name="TNew">ΠΠΎΠ²ΡΠΉ ΡΠΈΠΏ ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΠ°.</typeparam> | |
350 | /// <param name="mapper">ΠΡΠ΅ΠΎΠ±ΡΠ°Π·ΠΎΠ²Π°Π½ΠΈΠ΅ ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΠ° ΠΊ Π½ΠΎΠ²ΠΎΠΌΡ ΡΠΈΠΏΡ.</param> |
|
350 | /// <param name="mapper">ΠΡΠ΅ΠΎΠ±ΡΠ°Π·ΠΎΠ²Π°Π½ΠΈΠ΅ ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΠ° ΠΊ Π½ΠΎΠ²ΠΎΠΌΡ ΡΠΈΠΏΡ.</param> | |
351 | /// <param name="error">ΠΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊ ΠΎΡΠΈΠ±ΠΊΠΈ. ΠΠ°Π½Π½ΡΠΉ ΠΎΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊ ΠΏΠΎΠ»ΡΡΠΈΡ |
|
351 | /// <param name="error">ΠΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊ ΠΎΡΠΈΠ±ΠΊΠΈ. ΠΠ°Π½Π½ΡΠΉ ΠΎΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊ ΠΏΠΎΠ»ΡΡΠΈΡ | |
352 | /// ΠΈΡΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅ Π²ΠΎΠ·Π½ΠΈΠΊΡΠ΅Π΅ ΠΏΡΠΈ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΠΈ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ.</param> |
|
352 | /// ΠΈΡΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅ Π²ΠΎΠ·Π½ΠΈΠΊΡΠ΅Π΅ ΠΏΡΠΈ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΠΈ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ.</param> | |
353 | /// <returns>ΠΠΎΠ²ΠΎΠ΅ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅, ΠΊΠΎΡΠΎΡΠΎΠ΅ Π±ΡΠ΄Π΅Ρ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΎ ΠΏΡΠΈ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΠΈ ΠΈΡΡ ΠΎΠ΄Π½ΠΎΠ³ΠΎ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ.</returns> |
|
353 | /// <returns>ΠΠΎΠ²ΠΎΠ΅ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅, ΠΊΠΎΡΠΎΡΠΎΠ΅ Π±ΡΠ΄Π΅Ρ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΎ ΠΏΡΠΈ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΠΈ ΠΈΡΡ ΠΎΠ΄Π½ΠΎΠ³ΠΎ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ.</returns> | |
354 | /// <param name = "cancel"></param> |
|
354 | /// <param name = "cancel"></param> | |
355 | public IPromise<TNew> Then<TNew>(ResultMapper<T, TNew> mapper, ErrorHandler<TNew> error, Action cancel) { |
|
355 | public IPromise<TNew> Then<TNew>(ResultMapper<T, TNew> mapper, ErrorHandler<TNew> error, Action cancel) { | |
356 | Safe.ArgumentNotNull(mapper, "mapper"); |
|
356 | Safe.ArgumentNotNull(mapper, "mapper"); | |
357 |
|
357 | |||
358 | // ΡΠΎΠ·Π΄Π°Π΅ΠΌ ΠΏΡΠΈΡΠ΅ΠΏΠ»Π΅Π½Π½ΠΎΠ΅ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅ |
|
358 | // ΡΠΎΠ·Π΄Π°Π΅ΠΌ ΠΏΡΠΈΡΠ΅ΠΏΠ»Π΅Π½Π½ΠΎΠ΅ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅ | |
359 | var medium = new Promise<TNew>(this, true); |
|
359 | var medium = new Promise<TNew>(this, true); | |
360 |
|
360 | |||
361 | ResultHandler<T> resultHandler = result => medium.Resolve(mapper(result)); |
|
361 | ResultHandler<T> resultHandler = result => medium.Resolve(mapper(result)); | |
362 | ErrorHandler<T> errorHandler; |
|
362 | ErrorHandler<T> errorHandler; | |
363 | if (error != null) |
|
363 | if (error != null) | |
364 | errorHandler = e => { |
|
364 | errorHandler = e => { | |
365 | try { |
|
365 | try { | |
366 | medium.Resolve(error(e)); |
|
366 | medium.Resolve(error(e)); | |
367 | } catch (Exception e2) { |
|
367 | } catch (Exception e2) { | |
368 | // Π² ΡΠ»ΡΡΠ°Π΅ ΠΎΡΠΈΠ±ΠΊΠΈ Π½ΡΠΆΠ½ΠΎ ΠΏΠ΅ΡΠ΅Π΄Π°ΡΡ ΠΈΡΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅ Π΄Π°Π»ΡΡΠ΅ ΠΏΠΎ ΡΠ΅ΠΏΠΎΡΠΊΠ΅ |
|
368 | // Π² ΡΠ»ΡΡΠ°Π΅ ΠΎΡΠΈΠ±ΠΊΠΈ Π½ΡΠΆΠ½ΠΎ ΠΏΠ΅ΡΠ΅Π΄Π°ΡΡ ΠΈΡΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅ Π΄Π°Π»ΡΡΠ΅ ΠΏΠΎ ΡΠ΅ΠΏΠΎΡΠΊΠ΅ | |
369 | medium.Reject(e2); |
|
369 | medium.Reject(e2); | |
370 | } |
|
370 | } | |
371 | return default(T); |
|
371 | return default(T); | |
372 | }; |
|
372 | }; | |
373 | else |
|
373 | else | |
374 | errorHandler = e => { |
|
374 | errorHandler = e => { | |
375 | medium.Reject(e); |
|
375 | medium.Reject(e); | |
376 | return default(T); |
|
376 | return default(T); | |
377 | }; |
|
377 | }; | |
378 |
|
378 | |||
379 | Action cancelHandler; |
|
379 | Action cancelHandler; | |
380 | if (cancel != null) |
|
380 | if (cancel != null) | |
381 | cancelHandler = () => { |
|
381 | cancelHandler = () => { | |
382 | cancel(); |
|
382 | cancel(); | |
383 | medium.Cancel(); |
|
383 | medium.Cancel(); | |
384 | }; |
|
384 | }; | |
385 | else |
|
385 | else | |
386 | cancelHandler = medium.Cancel; |
|
386 | cancelHandler = medium.Cancel; | |
387 |
|
387 | |||
388 |
|
388 | |||
389 | AddHandler( |
|
389 | AddHandler( | |
390 | resultHandler, |
|
390 | resultHandler, | |
391 | errorHandler, |
|
391 | errorHandler, | |
392 | cancelHandler, |
|
392 | cancelHandler, | |
393 | null |
|
393 | null | |
394 | ); |
|
394 | ); | |
395 |
|
395 | |||
396 | return medium; |
|
396 | return medium; | |
397 | } |
|
397 | } | |
398 |
|
398 | |||
399 | public IPromise<TNew> Then<TNew>(ResultMapper<T, TNew> mapper, ErrorHandler<TNew> error) { |
|
399 | public IPromise<TNew> Then<TNew>(ResultMapper<T, TNew> mapper, ErrorHandler<TNew> error) { | |
400 | return Then(mapper, error, null); |
|
400 | return Then(mapper, error, null); | |
401 | } |
|
401 | } | |
402 |
|
402 | |||
403 | public IPromise<TNew> Then<TNew>(ResultMapper<T, TNew> mapper) { |
|
403 | public IPromise<TNew> Then<TNew>(ResultMapper<T, TNew> mapper) { | |
404 | return Then(mapper, null, null); |
|
404 | return Then(mapper, null, null); | |
405 | } |
|
405 | } | |
406 |
|
406 | |||
407 | /// <summary> |
|
407 | /// <summary> | |
408 | /// Π‘ΡΠ΅ΠΏΠ»ΡΠ΅Ρ Π½Π΅ΡΠΊΠΎΠ»ΡΠΊΠΎ Π°ΡΠ½Ρ ΡΠΎΠ½Π½ΡΡ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΉ. Π£ΠΊΠ°Π·Π°Π½Π½Π°Ρ Π°ΡΠΈΠ½Ρ ΡΠΎΠ½Π½Π°Ρ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΡ Π±ΡΠ΄Π΅Ρ Π²ΡΠ·Π²Π°Π½Π° ΠΏΠΎΡΠ»Π΅ |
|
408 | /// Π‘ΡΠ΅ΠΏΠ»ΡΠ΅Ρ Π½Π΅ΡΠΊΠΎΠ»ΡΠΊΠΎ Π°ΡΠ½Ρ ΡΠΎΠ½Π½ΡΡ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΉ. Π£ΠΊΠ°Π·Π°Π½Π½Π°Ρ Π°ΡΠΈΠ½Ρ ΡΠΎΠ½Π½Π°Ρ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΡ Π±ΡΠ΄Π΅Ρ Π²ΡΠ·Π²Π°Π½Π° ΠΏΠΎΡΠ»Π΅ | |
409 | /// Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΡ ΡΠ΅ΠΊΡΡΠ΅ΠΉ, Π° ΡΠ΅Π·ΡΠ»ΡΡΠ°Ρ ΡΠ΅ΠΊΡΡΠ΅ΠΉ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ ΠΌΠΎΠΆΠ΅Ρ Π±ΡΡΡ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½ Π΄Π»Ρ ΠΈΠ½ΠΈΡΠΈΠ°Π»ΠΈΠ·Π°ΡΠΈΠΈ |
|
409 | /// Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΡ ΡΠ΅ΠΊΡΡΠ΅ΠΉ, Π° ΡΠ΅Π·ΡΠ»ΡΡΠ°Ρ ΡΠ΅ΠΊΡΡΠ΅ΠΉ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ ΠΌΠΎΠΆΠ΅Ρ Π±ΡΡΡ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½ Π΄Π»Ρ ΠΈΠ½ΠΈΡΠΈΠ°Π»ΠΈΠ·Π°ΡΠΈΠΈ | |
410 | /// Π½ΠΎΠ²ΠΎΠΉ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ. |
|
410 | /// Π½ΠΎΠ²ΠΎΠΉ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ. | |
411 | /// </summary> |
|
411 | /// </summary> | |
412 | /// <typeparam name="TNew">Π’ΠΈΠΏ ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΠ° ΡΠΊΠ°Π·Π°Π½Π½ΠΎΠΉ Π°ΡΠΈΠ½Ρ ΡΠΎΠ½Π½ΠΎΠΉ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ.</typeparam> |
|
412 | /// <typeparam name="TNew">Π’ΠΈΠΏ ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΠ° ΡΠΊΠ°Π·Π°Π½Π½ΠΎΠΉ Π°ΡΠΈΠ½Ρ ΡΠΎΠ½Π½ΠΎΠΉ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ.</typeparam> | |
413 | /// <param name="chained">ΠΡΠΈΠ½Ρ ΡΠΎΠ½Π½Π°Ρ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΡ, ΠΊΠΎΡΠΎΡΠ°Ρ Π΄ΠΎΠ»ΠΆΠ½Π° Π±ΡΠ΄Π΅Ρ Π½Π°ΡΠ°ΡΡΡΡ ΠΏΠΎΡΠ»Π΅ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΡ ΡΠ΅ΠΊΡΡΠ΅ΠΉ.</param> |
|
413 | /// <param name="chained">ΠΡΠΈΠ½Ρ ΡΠΎΠ½Π½Π°Ρ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΡ, ΠΊΠΎΡΠΎΡΠ°Ρ Π΄ΠΎΠ»ΠΆΠ½Π° Π±ΡΠ΄Π΅Ρ Π½Π°ΡΠ°ΡΡΡΡ ΠΏΠΎΡΠ»Π΅ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΡ ΡΠ΅ΠΊΡΡΠ΅ΠΉ.</param> | |
414 | /// <param name="error">ΠΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊ ΠΎΡΠΈΠ±ΠΊΠΈ. ΠΠ°Π½Π½ΡΠΉ ΠΎΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊ ΠΏΠΎΠ»ΡΡΠΈΡ |
|
414 | /// <param name="error">ΠΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊ ΠΎΡΠΈΠ±ΠΊΠΈ. ΠΠ°Π½Π½ΡΠΉ ΠΎΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊ ΠΏΠΎΠ»ΡΡΠΈΡ | |
415 | /// ΠΈΡΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅ Π²ΠΎΠ·Π½ΠΈΠΊΡΠ΅Π΅ ΠΏΡΠΈ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΠΈ ΡΠ΅ΠΊΡΠ΅ΡΠΉ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ.</param> |
|
415 | /// ΠΈΡΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅ Π²ΠΎΠ·Π½ΠΈΠΊΡΠ΅Π΅ ΠΏΡΠΈ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΠΈ ΡΠ΅ΠΊΡΠ΅ΡΠΉ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ.</param> | |
416 | /// <returns>ΠΠΎΠ²ΠΎΠ΅ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅, ΠΊΠΎΡΠΎΡΠΎΠ΅ Π±ΡΠ΄Π΅Ρ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΎ ΠΏΠΎ ΠΎΠΊΠΎΠ½ΡΠ°Π½ΠΈΡ ΡΠΊΠ°Π·Π°Π½Π½ΠΎΠΉ Π°ΡΠ½Ρ ΡΠΎΠ½Π½ΠΎΠΉ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ.</returns> |
|
416 | /// <returns>ΠΠΎΠ²ΠΎΠ΅ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅, ΠΊΠΎΡΠΎΡΠΎΠ΅ Π±ΡΠ΄Π΅Ρ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΎ ΠΏΠΎ ΠΎΠΊΠΎΠ½ΡΠ°Π½ΠΈΡ ΡΠΊΠ°Π·Π°Π½Π½ΠΎΠΉ Π°ΡΠ½Ρ ΡΠΎΠ½Π½ΠΎΠΉ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ.</returns> | |
417 | /// <param name = "cancel"></param> |
|
417 | /// <param name = "cancel"></param> | |
418 | public IPromise<TNew> Chain<TNew>(ResultMapper<T, IPromise<TNew>> chained, ErrorHandler<IPromise<TNew>> error, Action cancel) { |
|
418 | public IPromise<TNew> Chain<TNew>(ResultMapper<T, IPromise<TNew>> chained, ErrorHandler<IPromise<TNew>> error, Action cancel) { | |
419 |
|
419 | |||
420 | Safe.ArgumentNotNull(chained, "chained"); |
|
420 | Safe.ArgumentNotNull(chained, "chained"); | |
421 |
|
421 | |||
422 | // ΠΏΡΠΎΠ±Π»Π΅ΠΌΠ° Π² ΡΠΎΠΌ, ΡΡΠΎ Π½Π° ΠΌΠΎΠΌΠ΅Π½Ρ ΡΠ²ΡΠ·ΡΠ²Π°Π½ΠΈΡ Π΅ΡΠ΅ Π½Π΅ Π½Π°ΡΠ°ΡΠ° Π°ΡΠΈΠ½Ρ ΡΠΎΠ½Π½Π°Ρ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΡ, ΠΏΠΎΡΡΠΎΠΌΡ Π½ΡΠΆΠ½ΠΎ |
|
422 | // ΠΏΡΠΎΠ±Π»Π΅ΠΌΠ° Π² ΡΠΎΠΌ, ΡΡΠΎ Π½Π° ΠΌΠΎΠΌΠ΅Π½Ρ ΡΠ²ΡΠ·ΡΠ²Π°Π½ΠΈΡ Π΅ΡΠ΅ Π½Π΅ Π½Π°ΡΠ°ΡΠ° Π°ΡΠΈΠ½Ρ ΡΠΎΠ½Π½Π°Ρ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΡ, ΠΏΠΎΡΡΠΎΠΌΡ Π½ΡΠΆΠ½ΠΎ | |
423 | // ΡΠΎΠ·Π΄Π°ΡΡ ΠΏΠΎΡΡΠ΅Π΄Π½ΠΈΠΊΠ°, ΠΊ ΠΊΠΎΡΠΎΡΠΎΠΌΡ Π±ΡΠ΄ΡΡ ΠΏΠΎΠ΄Π²ΡΠ·ΡΠ²Π°ΡΡΡΡ ΡΠ»Π΅Π΄ΡΡΡΠΈΠ΅ ΠΎΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊΠΈ. |
|
423 | // ΡΠΎΠ·Π΄Π°ΡΡ ΠΏΠΎΡΡΠ΅Π΄Π½ΠΈΠΊΠ°, ΠΊ ΠΊΠΎΡΠΎΡΠΎΠΌΡ Π±ΡΠ΄ΡΡ ΠΏΠΎΠ΄Π²ΡΠ·ΡΠ²Π°ΡΡΡΡ ΡΠ»Π΅Π΄ΡΡΡΠΈΠ΅ ΠΎΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊΠΈ. | |
424 | // ΠΊΠΎΠ³Π΄Π° Π±ΡΠ΄Π΅Ρ Π²ΡΠΏΠΎΠ»Π½Π΅Π½Π° ΡΠ΅Π°Π»ΡΠ½Π°Ρ Π°ΡΠΈΠ½Ρ ΡΠΎΠ½Π½Π°Ρ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΡ, ΠΎΠ½Π° ΠΎΠ±ΡΠ°ΡΠΈΡΡΡΡ ΠΊ ΠΏΠΎΡΡΠ΅Π΄Π½ΠΈΠΊΡ, ΡΡΠΎΠ±Ρ |
|
424 | // ΠΊΠΎΠ³Π΄Π° Π±ΡΠ΄Π΅Ρ Π²ΡΠΏΠΎΠ»Π½Π΅Π½Π° ΡΠ΅Π°Π»ΡΠ½Π°Ρ Π°ΡΠΈΠ½Ρ ΡΠΎΠ½Π½Π°Ρ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΡ, ΠΎΠ½Π° ΠΎΠ±ΡΠ°ΡΠΈΡΡΡΡ ΠΊ ΠΏΠΎΡΡΠ΅Π΄Π½ΠΈΠΊΡ, ΡΡΠΎΠ±Ρ | |
425 | // ΠΏΠ΅ΡΠ΅Π΄Π°ΡΡ ΡΠ΅ΡΠ΅Π· Π½Π΅Π³ΠΎ ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΡ ΡΠ°Π±ΠΎΡΡ. |
|
425 | // ΠΏΠ΅ΡΠ΅Π΄Π°ΡΡ ΡΠ΅ΡΠ΅Π· Π½Π΅Π³ΠΎ ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΡ ΡΠ°Π±ΠΎΡΡ. | |
426 | var medium = new Promise<TNew>(this, true); |
|
426 | var medium = new Promise<TNew>(this, true); | |
427 |
|
427 | |||
428 | ResultHandler<T> resultHandler = delegate(T result) { |
|
428 | ResultHandler<T> resultHandler = delegate(T result) { | |
429 | if (medium.IsCancelled) |
|
429 | if (medium.IsCancelled) | |
430 | return; |
|
430 | return; | |
431 |
|
431 | |||
432 | var promise = chained(result); |
|
432 | var promise = chained(result); | |
433 |
|
433 | |||
434 | promise.Last( |
|
434 | promise.Last( | |
435 | medium.Resolve, |
|
435 | medium.Resolve, | |
436 | medium.Reject, |
|
436 | medium.Reject, | |
437 | () => medium.Reject(new OperationCanceledException()) // Π²Π½Π΅ΡΠ½ΡΡ ΠΎΡΠΌΠ΅Π½Π° ΡΠ²ΡΠ·Π°Π½Π½ΠΎΠΉ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ ΡΠ°ΡΡΠΌΠ°ΡΡΠΈΠ²Π°Π΅ΡΡΡ ΠΊΠ°ΠΊ ΠΎΡΠΈΠ±ΠΊΠ° |
|
437 | () => medium.Reject(new OperationCanceledException()) // Π²Π½Π΅ΡΠ½ΡΡ ΠΎΡΠΌΠ΅Π½Π° ΡΠ²ΡΠ·Π°Π½Π½ΠΎΠΉ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ ΡΠ°ΡΡΠΌΠ°ΡΡΠΈΠ²Π°Π΅ΡΡΡ ΠΊΠ°ΠΊ ΠΎΡΠΈΠ±ΠΊΠ° | |
438 | ); |
|
438 | ); | |
439 |
|
439 | |||
440 | // notify chained operation that it's not needed anymore |
|
440 | // notify chained operation that it's not needed anymore | |
441 | // ΠΏΠΎΡΡΠ΄ΠΎΠΊ Π²ΡΠ·ΠΎΠ²Π° Then, Cancelled Π²Π°ΠΆΠ΅Π½, ΠΏΠΎΡΠΊΠΎΠ»ΡΠΊΡ ΠΎΡ ΡΡΠΎΠ³ΠΎ |
|
441 | // ΠΏΠΎΡΡΠ΄ΠΎΠΊ Π²ΡΠ·ΠΎΠ²Π° Then, Cancelled Π²Π°ΠΆΠ΅Π½, ΠΏΠΎΡΠΊΠΎΠ»ΡΠΊΡ ΠΎΡ ΡΡΠΎΠ³ΠΎ | |
442 | // Π·Π°Π²ΠΈΡΠΈΡ IsExclusive |
|
442 | // Π·Π°Π²ΠΈΡΠΈΡ IsExclusive | |
443 | medium.Cancelled(() => { |
|
443 | medium.Cancelled(() => { | |
444 | if (promise.IsExclusive) |
|
444 | if (promise.IsExclusive) | |
445 | promise.Cancel(); |
|
445 | promise.Cancel(); | |
446 | }); |
|
446 | }); | |
447 | }; |
|
447 | }; | |
448 |
|
448 | |||
449 | ErrorHandler<T> errorHandler; |
|
449 | ErrorHandler<T> errorHandler; | |
450 |
|
450 | |||
451 | if (error != null) |
|
451 | if (error != null) | |
452 | errorHandler = delegate(Exception e) { |
|
452 | errorHandler = delegate(Exception e) { | |
453 | try { |
|
453 | try { | |
454 | var promise = error(e); |
|
454 | var promise = error(e); | |
455 |
|
455 | |||
456 | promise.Last( |
|
456 | promise.Last( | |
457 | medium.Resolve, |
|
457 | medium.Resolve, | |
458 | medium.Reject, |
|
458 | medium.Reject, | |
459 | () => medium.Reject(new OperationCanceledException()) // Π²Π½Π΅ΡΠ½ΡΡ ΠΎΡΠΌΠ΅Π½Π° ΡΠ²ΡΠ·Π°Π½Π½ΠΎΠΉ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ ΡΠ°ΡΡΠΌΠ°ΡΡΠΈΠ²Π°Π΅ΡΡΡ ΠΊΠ°ΠΊ ΠΎΡΠΈΠ±ΠΊΠ° |
|
459 | () => medium.Reject(new OperationCanceledException()) // Π²Π½Π΅ΡΠ½ΡΡ ΠΎΡΠΌΠ΅Π½Π° ΡΠ²ΡΠ·Π°Π½Π½ΠΎΠΉ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ ΡΠ°ΡΡΠΌΠ°ΡΡΠΈΠ²Π°Π΅ΡΡΡ ΠΊΠ°ΠΊ ΠΎΡΠΈΠ±ΠΊΠ° | |
460 | ); |
|
460 | ); | |
461 |
|
461 | |||
462 | // notify chained operation that it's not needed anymore |
|
462 | // notify chained operation that it's not needed anymore | |
463 | // ΠΏΠΎΡΡΠ΄ΠΎΠΊ Π²ΡΠ·ΠΎΠ²Π° Then, Cancelled Π²Π°ΠΆΠ΅Π½, ΠΏΠΎΡΠΊΠΎΠ»ΡΠΊΡ ΠΎΡ ΡΡΠΎΠ³ΠΎ |
|
463 | // ΠΏΠΎΡΡΠ΄ΠΎΠΊ Π²ΡΠ·ΠΎΠ²Π° Then, Cancelled Π²Π°ΠΆΠ΅Π½, ΠΏΠΎΡΠΊΠΎΠ»ΡΠΊΡ ΠΎΡ ΡΡΠΎΠ³ΠΎ | |
464 | // Π·Π°Π²ΠΈΡΠΈΡ IsExclusive |
|
464 | // Π·Π°Π²ΠΈΡΠΈΡ IsExclusive | |
465 | medium.Cancelled(() => { |
|
465 | medium.Cancelled(() => { | |
466 | if (promise.IsExclusive) |
|
466 | if (promise.IsExclusive) | |
467 | promise.Cancel(); |
|
467 | promise.Cancel(); | |
468 | }); |
|
468 | }); | |
469 | } catch (Exception e2) { |
|
469 | } catch (Exception e2) { | |
470 | medium.Reject(e2); |
|
470 | medium.Reject(e2); | |
471 | } |
|
471 | } | |
472 | return default(T); |
|
472 | return default(T); | |
473 | }; |
|
473 | }; | |
474 | else |
|
474 | else | |
475 | errorHandler = err => { |
|
475 | errorHandler = err => { | |
476 | medium.Reject(err); |
|
476 | medium.Reject(err); | |
477 | return default(T); |
|
477 | return default(T); | |
478 | }; |
|
478 | }; | |
479 |
|
479 | |||
480 |
|
480 | |||
481 | Action cancelHandler; |
|
481 | Action cancelHandler; | |
482 | if (cancel != null) |
|
482 | if (cancel != null) | |
483 | cancelHandler = () => { |
|
483 | cancelHandler = () => { | |
484 | if (cancel != null) |
|
484 | if (cancel != null) | |
485 | cancel(); |
|
485 | cancel(); | |
486 | medium.Cancel(); |
|
486 | medium.Cancel(); | |
487 | }; |
|
487 | }; | |
488 | else |
|
488 | else | |
489 | cancelHandler = medium.Cancel; |
|
489 | cancelHandler = medium.Cancel; | |
490 |
|
490 | |||
491 | AddHandler( |
|
491 | AddHandler( | |
492 | resultHandler, |
|
492 | resultHandler, | |
493 | errorHandler, |
|
493 | errorHandler, | |
494 | cancelHandler, |
|
494 | cancelHandler, | |
495 | null |
|
495 | null | |
496 | ); |
|
496 | ); | |
497 |
|
497 | |||
498 | return medium; |
|
498 | return medium; | |
499 | } |
|
499 | } | |
500 |
|
500 | |||
501 | public IPromise<TNew> Chain<TNew>(ResultMapper<T, IPromise<TNew>> chained, ErrorHandler<IPromise<TNew>> error) { |
|
501 | public IPromise<TNew> Chain<TNew>(ResultMapper<T, IPromise<TNew>> chained, ErrorHandler<IPromise<TNew>> error) { | |
502 | return Chain(chained, error, null); |
|
502 | return Chain(chained, error, null); | |
503 | } |
|
503 | } | |
504 |
|
504 | |||
505 | public IPromise<TNew> Chain<TNew>(ResultMapper<T, IPromise<TNew>> chained) { |
|
505 | public IPromise<TNew> Chain<TNew>(ResultMapper<T, IPromise<TNew>> chained) { | |
506 | return Chain(chained, null, null); |
|
506 | return Chain(chained, null, null); | |
507 | } |
|
507 | } | |
508 |
|
508 | |||
509 | public IPromise<T> Cancelled(Action handler) { |
|
509 | public IPromise<T> Cancelled(Action handler) { | |
510 | var medium = new Promise<T>(this,true); |
|
510 | var medium = new Promise<T>(this,true); | |
511 | AddHandler(null, null, handler, medium); |
|
511 | AddHandler(null, null, handler, medium); | |
512 | return medium; |
|
512 | return medium; | |
513 | } |
|
513 | } | |
514 |
|
514 | |||
515 | /// <summary> |
|
515 | /// <summary> | |
516 | /// Adds the specified handler for all cases (success, error, cancel) |
|
516 | /// Adds the specified handler for all cases (success, error, cancel) | |
517 | /// </summary> |
|
517 | /// </summary> | |
518 | /// <param name="handler">The handler that will be called anyway</param> |
|
518 | /// <param name="handler">The handler that will be called anyway</param> | |
519 | /// <returns>self</returns> |
|
519 | /// <returns>self</returns> | |
520 | public IPromise<T> Anyway(Action handler) { |
|
520 | public IPromise<T> Anyway(Action handler) { | |
521 | Safe.ArgumentNotNull(handler, "handler"); |
|
521 | Safe.ArgumentNotNull(handler, "handler"); | |
522 |
|
522 | |||
523 | AddHandler( |
|
523 | AddHandler( | |
524 | x => handler(), |
|
524 | x => handler(), | |
525 | e => { |
|
525 | e => { | |
526 | handler(); |
|
526 | handler(); | |
527 | throw new TransientPromiseException(e); |
|
527 | throw new TransientPromiseException(e); | |
528 | }, |
|
528 | }, | |
529 | handler, |
|
529 | handler, | |
530 | null |
|
530 | null | |
531 | ); |
|
531 | ); | |
532 | return this; |
|
532 | return this; | |
533 | } |
|
533 | } | |
534 |
|
534 | |||
535 | /// <summary> |
|
535 | /// <summary> | |
536 | /// ΠΡΠ΅ΠΎΠ±ΡΠ°Π·ΡΠ΅Ρ ΡΠ΅Π·ΡΠ»ΡΡΠ°Ρ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ ΠΊ Π½ΡΠΆΠ½ΠΎΠΌΡ ΡΠΈΠΏΡ |
|
536 | /// ΠΡΠ΅ΠΎΠ±ΡΠ°Π·ΡΠ΅Ρ ΡΠ΅Π·ΡΠ»ΡΡΠ°Ρ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ ΠΊ Π½ΡΠΆΠ½ΠΎΠΌΡ ΡΠΈΠΏΡ | |
537 | /// </summary> |
|
537 | /// </summary> | |
538 | /// <typeparam name="T2"></typeparam> |
|
538 | /// <typeparam name="T2"></typeparam> | |
539 | /// <returns></returns> |
|
539 | /// <returns></returns> | |
540 | public IPromise<T2> Cast<T2>() { |
|
540 | public IPromise<T2> Cast<T2>() { | |
541 | return Then(x => (T2)(object)x, null); |
|
541 | return Then(x => (T2)(object)x, null); | |
542 | } |
|
542 | } | |
543 |
|
543 | |||
544 | /// <summary> |
|
544 | /// <summary> | |
545 | /// ΠΠΎΠΆΠΈΠ΄Π°Π΅ΡΡΡ ΠΎΡΠ»ΠΎΠΆΠ΅Π½Π½ΠΎΠ³ΠΎ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ ΠΈ Π² ΡΠ»ΡΡΠ°Π΅ ΡΡΠΏΠ΅Ρ Π°, Π²ΠΎΠ·Π²ΡΠ°ΡΠ°Π΅Ρ |
|
545 | /// ΠΠΎΠΆΠΈΠ΄Π°Π΅ΡΡΡ ΠΎΡΠ»ΠΎΠΆΠ΅Π½Π½ΠΎΠ³ΠΎ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ ΠΈ Π² ΡΠ»ΡΡΠ°Π΅ ΡΡΠΏΠ΅Ρ Π°, Π²ΠΎΠ·Π²ΡΠ°ΡΠ°Π΅Ρ | |
546 | /// Π΅Π³ΠΎ, ΡΠ΅Π·ΡΠ»ΡΡΠ°Ρ, Π² ΠΏΡΠΎΡΠΈΠ²Π½ΠΎΠΌ ΡΠ»ΡΡΠ°Π΅ Π±ΡΠΎΡΠ°Π΅Ρ ΠΈΡΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅. |
|
546 | /// Π΅Π³ΠΎ, ΡΠ΅Π·ΡΠ»ΡΡΠ°Ρ, Π² ΠΏΡΠΎΡΠΈΠ²Π½ΠΎΠΌ ΡΠ»ΡΡΠ°Π΅ Π±ΡΠΎΡΠ°Π΅Ρ ΠΈΡΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅. | |
547 | /// </summary> |
|
547 | /// </summary> | |
548 | /// <remarks> |
|
548 | /// <remarks> | |
549 | /// <para> |
|
549 | /// <para> | |
550 | /// ΠΡΠ»ΠΈ ΠΎΠΆΠΈΠ΄Π°Π½ΠΈΠ΅ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ Π±ΡΠ»ΠΎ ΠΏΡΠ΅ΡΠ²Π°Π½ΠΎ ΠΏΠΎ ΡΠ°ΠΉΠΌΠ°ΡΡΡ, ΡΡΠΎ Π½Π΅ Π·Π½Π°ΡΠΈΡ, |
|
550 | /// ΠΡΠ»ΠΈ ΠΎΠΆΠΈΠ΄Π°Π½ΠΈΠ΅ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ Π±ΡΠ»ΠΎ ΠΏΡΠ΅ΡΠ²Π°Π½ΠΎ ΠΏΠΎ ΡΠ°ΠΉΠΌΠ°ΡΡΡ, ΡΡΠΎ Π½Π΅ Π·Π½Π°ΡΠΈΡ, | |
551 | /// ΡΡΠΎ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅ Π±ΡΠ»ΠΎ ΠΎΡΠΌΠ΅Π½Π΅Π½ΠΎ ΠΈΠ»ΠΈ ΡΡΠΎ-ΡΠΎ Π² ΡΡΠΎΠΌ ΡΠΎΠ΄Π΅, ΡΡΠΎ ΡΠΎΠ»ΡΠΊΠΎ |
|
551 | /// ΡΡΠΎ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅ Π±ΡΠ»ΠΎ ΠΎΡΠΌΠ΅Π½Π΅Π½ΠΎ ΠΈΠ»ΠΈ ΡΡΠΎ-ΡΠΎ Π² ΡΡΠΎΠΌ ΡΠΎΠ΄Π΅, ΡΡΠΎ ΡΠΎΠ»ΡΠΊΠΎ | |
552 | /// ΠΎΠ·Π½Π°ΡΠ°Π΅Ρ, ΡΡΠΎ ΠΌΡ Π΅Π³ΠΎ Π½Π΅ Π΄ΠΎΠΆΠ΄Π°Π»ΠΈΡΡ, ΠΎΠ΄Π½Π°ΠΊΠΎ Π²ΡΠ΅ Π·Π°ΡΠ΅Π³ΠΈΡΡΡΠΈΡΠΎΠ²Π°Π½Π½ΡΠ΅ |
|
552 | /// ΠΎΠ·Π½Π°ΡΠ°Π΅Ρ, ΡΡΠΎ ΠΌΡ Π΅Π³ΠΎ Π½Π΅ Π΄ΠΎΠΆΠ΄Π°Π»ΠΈΡΡ, ΠΎΠ΄Π½Π°ΠΊΠΎ Π²ΡΠ΅ Π·Π°ΡΠ΅Π³ΠΈΡΡΡΠΈΡΠΎΠ²Π°Π½Π½ΡΠ΅ | |
553 | /// ΠΎΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊΠΈ, ΠΊΠ°ΠΊ Π±ΡΠ»ΠΈ ΡΠ°ΠΊ ΠΎΡΡΠ°Π»ΠΈΡΡ ΠΈ ΠΎΠ½ΠΈ Π±ΡΠ΄ΡΡ Π²ΡΠ·Π²Π°Π½Ρ, ΠΊΠΎΠ³Π΄Π° |
|
553 | /// ΠΎΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊΠΈ, ΠΊΠ°ΠΊ Π±ΡΠ»ΠΈ ΡΠ°ΠΊ ΠΎΡΡΠ°Π»ΠΈΡΡ ΠΈ ΠΎΠ½ΠΈ Π±ΡΠ΄ΡΡ Π²ΡΠ·Π²Π°Π½Ρ, ΠΊΠΎΠ³Π΄Π° | |
554 | /// ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅ Π±ΡΠ΄Π΅Ρ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΎ. |
|
554 | /// ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅ Π±ΡΠ΄Π΅Ρ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΎ. | |
555 | /// </para> |
|
555 | /// </para> | |
556 | /// <para> |
|
556 | /// <para> | |
557 | /// Π’Π°ΠΊΠΎΠ΅ ΠΏΠΎΠ²Π΅Π΄Π΅Π½ΠΈΠ΅ Π²ΠΏΠΎΠ»Π½Π΅ ΠΎΠΏΡΠ°Π²Π΄Π°Π½ΠΎ ΠΏΠΎΡΠΊΠΎΠ»ΡΠΊΡ ΡΠ°ΠΉΠΌΠ°ΡΡ ΠΌΠΎΠΆΠ΅Ρ ΠΈΡΡΠ΅ΡΡ |
|
557 | /// Π’Π°ΠΊΠΎΠ΅ ΠΏΠΎΠ²Π΅Π΄Π΅Π½ΠΈΠ΅ Π²ΠΏΠΎΠ»Π½Π΅ ΠΎΠΏΡΠ°Π²Π΄Π°Π½ΠΎ ΠΏΠΎΡΠΊΠΎΠ»ΡΠΊΡ ΡΠ°ΠΉΠΌΠ°ΡΡ ΠΌΠΎΠΆΠ΅Ρ ΠΈΡΡΠ΅ΡΡ | |
558 | /// Π² ΡΠΎΡ ΠΌΠΎΠΌΠ΅Π½Ρ, ΠΊΠΎΠ³Π΄Π° Π½Π°ΡΠ°Π»Π°ΡΡ ΠΎΠ±ΡΠ°Π±ΠΎΡΠΊΠ° ΡΠ΅ΠΏΠΎΡΠΊΠΈ ΠΎΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊΠΎΠ², ΠΈ |
|
558 | /// Π² ΡΠΎΡ ΠΌΠΎΠΌΠ΅Π½Ρ, ΠΊΠΎΠ³Π΄Π° Π½Π°ΡΠ°Π»Π°ΡΡ ΠΎΠ±ΡΠ°Π±ΠΎΡΠΊΠ° ΡΠ΅ΠΏΠΎΡΠΊΠΈ ΠΎΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊΠΎΠ², ΠΈ | |
559 | /// ΠΊ ΡΠΎΠΌΡ ΠΆΠ΅ ΡΠ΅ΠΊΡΡΠ΅Π΅ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅ ΠΌΠΎΠΆΠ΅Ρ ΡΡΠΎΡΡΡ Π² ΡΠ΅ΠΏΠΎΡΠΊΠ΅ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠΉ ΠΈ Π΅Π³ΠΎ |
|
559 | /// ΠΊ ΡΠΎΠΌΡ ΠΆΠ΅ ΡΠ΅ΠΊΡΡΠ΅Π΅ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅ ΠΌΠΎΠΆΠ΅Ρ ΡΡΠΎΡΡΡ Π² ΡΠ΅ΠΏΠΎΡΠΊΠ΅ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠΉ ΠΈ Π΅Π³ΠΎ | |
560 | /// ΠΎΡΠΊΠ»ΠΎΠ½Π΅Π½ΠΈΠ΅ ΠΌΠΎΠΆΠ΅Ρ ΠΏΡΠΈΠ²Π΅ΡΡΠΈ ΠΊ Π½Π΅ΠΏΡΠΎΠ³Π½ΠΎΠ·ΠΈΡΡΠ΅ΠΌΠΎΠΌΡ ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΡ. |
|
560 | /// ΠΎΡΠΊΠ»ΠΎΠ½Π΅Π½ΠΈΠ΅ ΠΌΠΎΠΆΠ΅Ρ ΠΏΡΠΈΠ²Π΅ΡΡΠΈ ΠΊ Π½Π΅ΠΏΡΠΎΠ³Π½ΠΎΠ·ΠΈΡΡΠ΅ΠΌΠΎΠΌΡ ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΡ. | |
561 | /// </para> |
|
561 | /// </para> | |
562 | /// </remarks> |
|
562 | /// </remarks> | |
563 | /// <param name="timeout">ΠΡΠ΅ΠΌΡ ΠΎΠΆΠΈΠ΄Π°Π½ΠΈΡ</param> |
|
563 | /// <param name="timeout">ΠΡΠ΅ΠΌΡ ΠΎΠΆΠΈΠ΄Π°Π½ΠΈΡ</param> | |
564 | /// <returns>Π Π΅Π·ΡΠ»ΡΡΠ°Ρ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΡ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ</returns> |
|
564 | /// <returns>Π Π΅Π·ΡΠ»ΡΡΠ°Ρ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΡ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ</returns> | |
565 | public T Join(int timeout) { |
|
565 | public T Join(int timeout) { | |
566 | var evt = new ManualResetEvent(false); |
|
566 | var evt = new ManualResetEvent(false); | |
567 | Anyway(() => evt.Set()); |
|
567 | Anyway(() => evt.Set()); | |
568 |
|
568 | |||
569 | if (!evt.WaitOne(timeout, true)) |
|
569 | if (!evt.WaitOne(timeout, true)) | |
570 | throw new TimeoutException(); |
|
570 | throw new TimeoutException(); | |
571 |
|
571 | |||
572 | switch (m_state) { |
|
572 | switch (m_state) { | |
573 | case SUCCEEDED_STATE: |
|
573 | case SUCCEEDED_STATE: | |
574 | return m_result; |
|
574 | return m_result; | |
575 | case CANCELLED_STATE: |
|
575 | case CANCELLED_STATE: | |
576 | throw new OperationCanceledException(); |
|
576 | throw new OperationCanceledException(); | |
577 | case REJECTED_STATE: |
|
577 | case REJECTED_STATE: | |
578 | throw new TargetInvocationException(m_error); |
|
578 | throw new TargetInvocationException(m_error); | |
579 | default: |
|
579 | default: | |
580 | throw new ApplicationException(String.Format("Invalid promise state {0}", m_state)); |
|
580 | throw new ApplicationException(String.Format("Invalid promise state {0}", m_state)); | |
581 | } |
|
581 | } | |
582 | } |
|
582 | } | |
583 |
|
583 | |||
584 | public T Join() { |
|
584 | public T Join() { | |
585 | return Join(Timeout.Infinite); |
|
585 | return Join(Timeout.Infinite); | |
586 | } |
|
586 | } | |
587 |
|
587 | |||
588 | void AddHandler(ResultHandler<T> success, ErrorHandler<T> error, Action cancel, Promise<T> medium) { |
|
588 | void AddHandler(ResultHandler<T> success, ErrorHandler<T> error, Action cancel, Promise<T> medium) { | |
589 | if (success != null || error != null) |
|
589 | if (success != null || error != null) | |
590 | Interlocked.Increment(ref m_childrenCount); |
|
590 | Interlocked.Increment(ref m_childrenCount); | |
591 |
|
591 | |||
592 | var handler = new HandlerDescriptor { |
|
592 | var handler = new HandlerDescriptor { | |
593 | resultHandler = success, |
|
593 | resultHandler = success, | |
594 | errorHandler = error, |
|
594 | errorHandler = error, | |
595 | cancellHandler = cancel, |
|
595 | cancellHandler = cancel, | |
596 | medium = medium |
|
596 | medium = medium | |
597 | }; |
|
597 | }; | |
598 |
|
598 | |||
599 | bool queued; |
|
599 | bool queued; | |
600 |
|
600 | |||
601 | if (!IsResolved) { |
|
601 | if (!IsResolved) { | |
602 | m_handlers.Enqueue(handler); |
|
602 | m_handlers.Enqueue(handler); | |
603 | queued = true; |
|
603 | queued = true; | |
604 | } else { |
|
604 | } else { | |
605 | // the promise is in resolved state, just invoke the handled with minimum overhead |
|
605 | // the promise is in resolved state, just invoke the handled with minimum overhead | |
606 | queued = false; |
|
606 | queued = false; | |
607 | InvokeHandler(handler); |
|
607 | InvokeHandler(handler); | |
608 | } |
|
608 | } | |
609 |
|
609 | |||
610 | if (queued && IsResolved && m_handlers.TryDequeue(out handler)) |
|
610 | if (queued && IsResolved && m_handlers.TryDequeue(out handler)) | |
611 | // if the promise have been resolved while we was adding handler to the queue |
|
611 | // if the promise have been resolved while we was adding handler to the queue | |
612 | // we can't guarantee that someone is still processing it |
|
612 | // we can't guarantee that someone is still processing it | |
613 | // therefore we will fetch a handler from the queue and execute it |
|
613 | // therefore we will fetch a handler from the queue and execute it | |
614 | // note that fetched handler may be not the one that we have added |
|
614 | // note that fetched handler may be not the one that we have added | |
615 | // even we can fetch no handlers at all :) |
|
615 | // even we can fetch no handlers at all :) | |
616 | InvokeHandler(handler); |
|
616 | InvokeHandler(handler); | |
617 | } |
|
617 | } | |
618 |
|
618 | |||
619 | protected virtual void InvokeHandler(HandlerDescriptor handler) { |
|
619 | protected virtual void InvokeHandler(HandlerDescriptor handler) { | |
620 | switch (m_state) { |
|
620 | switch (m_state) { | |
621 | case SUCCEEDED_STATE: |
|
621 | case SUCCEEDED_STATE: | |
622 | handler.Resolve(m_result); |
|
622 | handler.Resolve(m_result); | |
623 | break; |
|
623 | break; | |
624 | case REJECTED_STATE: |
|
624 | case REJECTED_STATE: | |
625 | handler.Reject(m_error); |
|
625 | handler.Reject(m_error); | |
626 | break; |
|
626 | break; | |
627 | case CANCELLED_STATE: |
|
627 | case CANCELLED_STATE: | |
628 | handler.Cancel(); |
|
628 | handler.Cancel(); | |
629 | break; |
|
629 | break; | |
630 | default: |
|
630 | default: | |
631 | // do nothing |
|
631 | // do nothing | |
632 | return; |
|
632 | return; | |
633 | } |
|
633 | } | |
634 | } |
|
634 | } | |
635 |
|
635 | |||
636 | void OnStateChanged() { |
|
636 | void OnStateChanged() { | |
637 | HandlerDescriptor handler; |
|
637 | HandlerDescriptor handler; | |
638 | while (m_handlers.TryDequeue(out handler)) |
|
638 | while (m_handlers.TryDequeue(out handler)) | |
639 | InvokeHandler(handler); |
|
639 | InvokeHandler(handler); | |
640 | } |
|
640 | } | |
641 |
|
641 | |||
642 | public bool IsExclusive { |
|
642 | public bool IsExclusive { | |
643 | get { |
|
643 | get { | |
644 | return m_childrenCount <= 1; |
|
644 | return m_childrenCount <= 1; | |
645 | } |
|
645 | } | |
646 | } |
|
646 | } | |
647 |
|
647 | |||
648 | /// <summary> |
|
648 | /// <summary> | |
649 | /// ΠΠ±ΡΠ΅Π΄ΠΈΠ½ΡΠ΅Ρ Π½Π΅ΡΠΊΠΎΠ»ΡΠΊΠΎ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠΉ Π² ΠΎΠ΄Π½ΠΎ, ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΠΎΠΌ ΠΊΠΎΡΠΎΡΠΎΠ³ΠΎ ΡΠ²Π»ΡΠ΅ΡΡΡ ΠΌΠ°ΡΡΠΈΠ² ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΠΎΠ² Π΄ΡΡΠ³ΠΈΡ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠΉ. |
|
649 | /// ΠΠ±ΡΠ΅Π΄ΠΈΠ½ΡΠ΅Ρ Π½Π΅ΡΠΊΠΎΠ»ΡΠΊΠΎ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠΉ Π² ΠΎΠ΄Π½ΠΎ, ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΠΎΠΌ ΠΊΠΎΡΠΎΡΠΎΠ³ΠΎ ΡΠ²Π»ΡΠ΅ΡΡΡ ΠΌΠ°ΡΡΠΈΠ² ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΠΎΠ² Π΄ΡΡΠ³ΠΈΡ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠΉ. | |
650 | /// ΠΡΠ»ΠΈ Ρ ΠΎΡΡΠ±Ρ ΠΎΠ΄Π½ΠΎ ΠΈΠ· ΠΏΠ΅ΡΠ΅Π΄Π°Π½Π½ΡΡ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠΉ Π½Π΅ Π±ΡΠ΄Π΅Ρ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΎ, ΡΠΎ Π½ΠΎΠ²ΠΎΠ΅ ΠΎΠ±Π΅ΡΠ΅Π½ΠΈΠ΅ ΡΠΎΠΆΠ΅ Π½Π΅ Π±ΡΠ΄Π΅Ρ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΎ. |
|
650 | /// ΠΡΠ»ΠΈ Ρ ΠΎΡΡΠ±Ρ ΠΎΠ΄Π½ΠΎ ΠΈΠ· ΠΏΠ΅ΡΠ΅Π΄Π°Π½Π½ΡΡ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠΉ Π½Π΅ Π±ΡΠ΄Π΅Ρ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΎ, ΡΠΎ Π½ΠΎΠ²ΠΎΠ΅ ΠΎΠ±Π΅ΡΠ΅Π½ΠΈΠ΅ ΡΠΎΠΆΠ΅ Π½Π΅ Π±ΡΠ΄Π΅Ρ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΎ. | |
651 | /// ΠΡΠΈ ΠΎΡΠΌΠ΅Π½Π΅ Π½ΠΎΠ²ΠΎΠ³ΠΎ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ, ΠΏΠ΅ΡΠ΅Π΄Π°Π½Π½ΡΠ΅ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ ΡΠ°ΠΊΠΆΠ΅ Π±ΡΠ΄ΡΡ ΠΎΡΠΌΠ΅Π½Π΅Π½Ρ, Π΅ΡΠ»ΠΈ Π½ΠΈΠΊΡΠΎ Π±ΠΎΠ»ΡΡΠ΅ Π½Π° Π½ΠΈΡ Π½Π΅ ΠΏΠΎΠ΄ΠΏΠΈΡΠ°Π½. |
|
651 | /// ΠΡΠΈ ΠΎΡΠΌΠ΅Π½Π΅ Π½ΠΎΠ²ΠΎΠ³ΠΎ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ, ΠΏΠ΅ΡΠ΅Π΄Π°Π½Π½ΡΠ΅ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ ΡΠ°ΠΊΠΆΠ΅ Π±ΡΠ΄ΡΡ ΠΎΡΠΌΠ΅Π½Π΅Π½Ρ, Π΅ΡΠ»ΠΈ Π½ΠΈΠΊΡΠΎ Π±ΠΎΠ»ΡΡΠ΅ Π½Π° Π½ΠΈΡ Π½Π΅ ΠΏΠΎΠ΄ΠΏΠΈΡΠ°Π½. | |
652 | /// </summary> |
|
652 | /// </summary> | |
653 | /// <param name="promises">Π‘ΠΏΠΈΡΠΎΠΊ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠΉ. ΠΡΠ»ΠΈ ΡΠΏΠΈΡΠΎΠΊ ΠΏΡΡΡΠΎΠΉ, ΡΠΎ ΡΠ΅Π·ΡΠ»ΡΡΠΈΡΡΡΡΠ΅Π΅ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅ Π²ΠΎΠ·Π²ΡΠ°ΡΠ°Π΅ΡΡΡ ΡΠΆΠ΅ Π²ΡΠΏΠΎΠ»Π½Π΅Π½Π½ΡΠΌ.</param> |
|
653 | /// <param name="promises">Π‘ΠΏΠΈΡΠΎΠΊ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠΉ. ΠΡΠ»ΠΈ ΡΠΏΠΈΡΠΎΠΊ ΠΏΡΡΡΠΎΠΉ, ΡΠΎ ΡΠ΅Π·ΡΠ»ΡΡΠΈΡΡΡΡΠ΅Π΅ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅ Π²ΠΎΠ·Π²ΡΠ°ΡΠ°Π΅ΡΡΡ ΡΠΆΠ΅ Π²ΡΠΏΠΎΠ»Π½Π΅Π½Π½ΡΠΌ.</param> | |
654 | /// <returns>ΠΠ±Π΅ΡΠ°Π½ΠΈΠ΅ ΠΎΠ±ΡΠ΅Π΄ΠΈΠ½ΡΡΡΠ΅Π΅ Π² ΡΠ΅Π±Π΅ ΡΠ΅Π·ΡΠ»ΡΡΠ°Ρ ΠΏΠ΅ΡΠ΅Π΄Π°Π½Π½ΡΡ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠΉ.</returns> |
|
654 | /// <returns>ΠΠ±Π΅ΡΠ°Π½ΠΈΠ΅ ΠΎΠ±ΡΠ΅Π΄ΠΈΠ½ΡΡΡΠ΅Π΅ Π² ΡΠ΅Π±Π΅ ΡΠ΅Π·ΡΠ»ΡΡΠ°Ρ ΠΏΠ΅ΡΠ΅Π΄Π°Π½Π½ΡΡ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠΉ.</returns> | |
655 | /// <exception cref="ArgumentNullException"><paramref name="promises"/> Π½Π΅ ΠΌΠΎΠΆΠ΅Ρ Π±ΡΡΡ null</exception> |
|
655 | /// <exception cref="ArgumentNullException"><paramref name="promises"/> Π½Π΅ ΠΌΠΎΠΆΠ΅Ρ Π±ΡΡΡ null</exception> | |
656 | public static IPromise<T[]> CreateComposite(IList<IPromise<T>> promises) { |
|
656 | public static IPromise<T[]> CreateComposite(IList<IPromise<T>> promises) { | |
657 | if (promises == null) |
|
657 | if (promises == null) | |
658 | throw new ArgumentNullException(); |
|
658 | throw new ArgumentNullException(); | |
659 |
|
659 | |||
660 | // ΡΠΎΠ·Π΄Π°Π΅ΠΌ Π°ΠΊΠΊΡΠΌΡΠ»ΡΡΠΎΡ Π΄Π»Ρ ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΠΎΠ² ΠΈ ΡΠ΅Π·ΡΠ»ΡΡΠΈΡΡΡΡΠ΅Π΅ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅ |
|
660 | // ΡΠΎΠ·Π΄Π°Π΅ΠΌ Π°ΠΊΠΊΡΠΌΡΠ»ΡΡΠΎΡ Π΄Π»Ρ ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΠΎΠ² ΠΈ ΡΠ΅Π·ΡΠ»ΡΡΠΈΡΡΡΡΠ΅Π΅ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅ | |
661 | var result = new T[promises.Count]; |
|
661 | var result = new T[promises.Count]; | |
662 | var promise = new Promise<T[]>(); |
|
662 | var promise = new Promise<T[]>(); | |
663 |
|
663 | |||
664 | // special case |
|
664 | // special case | |
665 | if (promises.Count == 0) { |
|
665 | if (promises.Count == 0) { | |
666 | promise.Resolve(result); |
|
666 | promise.Resolve(result); | |
667 | return promise; |
|
667 | return promise; | |
668 | } |
|
668 | } | |
669 |
|
669 | |||
670 | int pending = promises.Count; |
|
670 | int pending = promises.Count; | |
671 |
|
671 | |||
672 | for (int i = 0; i < promises.Count; i++) { |
|
672 | for (int i = 0; i < promises.Count; i++) { | |
673 | var dest = i; |
|
673 | var dest = i; | |
674 |
|
674 | |||
675 | if (promises[i] != null) { |
|
675 | if (promises[i] != null) { | |
676 | promises[i].Then( |
|
676 | promises[i].Then( | |
677 | x => { |
|
677 | x => { | |
678 | result[dest] = x; |
|
678 | result[dest] = x; | |
679 | if (Interlocked.Decrement(ref pending) == 0) |
|
679 | if (Interlocked.Decrement(ref pending) == 0) | |
680 | promise.Resolve(result); |
|
680 | promise.Resolve(result); | |
681 | }, |
|
681 | }, | |
682 | e => { |
|
682 | e => { | |
683 | promise.Reject(e); |
|
683 | promise.Reject(e); | |
684 | return default(T); |
|
684 | return default(T); | |
685 | } |
|
685 | } | |
686 | ); |
|
686 | ); | |
687 | } else { |
|
687 | } else { | |
688 | if (Interlocked.Decrement(ref pending) == 0) |
|
688 | if (Interlocked.Decrement(ref pending) == 0) | |
689 | promise.Resolve(result); |
|
689 | promise.Resolve(result); | |
690 | } |
|
690 | } | |
691 | } |
|
691 | } | |
692 |
|
692 | |||
693 | promise.Cancelled( |
|
693 | promise.Cancelled( | |
694 | () => { |
|
694 | () => { | |
695 | foreach (var d in promises) |
|
695 | foreach (var d in promises) | |
696 | if (d != null && d.IsExclusive) |
|
696 | if (d != null && d.IsExclusive) | |
697 | d.Cancel(); |
|
697 | d.Cancel(); | |
698 | } |
|
698 | } | |
699 | ); |
|
699 | ); | |
700 |
|
700 | |||
701 | return promise; |
|
701 | return promise; | |
702 | } |
|
702 | } | |
703 |
|
703 | |||
704 | /// <summary> |
|
704 | /// <summary> | |
705 | /// ΠΠ±ΡΠ΅Π΄ΠΈΠ½ΡΠ΅Ρ Π½Π΅ΡΠΊΠΎΠ»ΡΠΊΠΎ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠΉ Π² ΠΎΠ΄Π½ΠΎ. Π Π΅Π·ΡΠ»ΡΡΠΈΡΡΡΡΠ΅Π΅ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅ Π±ΡΠ΄Π΅Ρ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΎ ΠΏΡΠΈ |
|
705 | /// ΠΠ±ΡΠ΅Π΄ΠΈΠ½ΡΠ΅Ρ Π½Π΅ΡΠΊΠΎΠ»ΡΠΊΠΎ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠΉ Π² ΠΎΠ΄Π½ΠΎ. Π Π΅Π·ΡΠ»ΡΡΠΈΡΡΡΡΠ΅Π΅ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅ Π±ΡΠ΄Π΅Ρ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΎ ΠΏΡΠΈ | |
706 | /// Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΠΈ Π²ΡΠ΅Ρ ΡΠΊΠ°Π·Π°Π½Π½ΡΡ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠΉ. ΠΡΠΈ ΡΡΠΎΠΌ Π²ΠΎΠ·Π²ΡΠ°ΡΠ°Π΅ΠΌΡΠ΅ Π·Π½Π°ΡΠ΅Π½ΠΈΡ ΠΏΠ΅ΡΠ²ΠΈΡΠ½ΡΡ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠΉ |
|
706 | /// Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΠΈ Π²ΡΠ΅Ρ ΡΠΊΠ°Π·Π°Π½Π½ΡΡ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠΉ. ΠΡΠΈ ΡΡΠΎΠΌ Π²ΠΎΠ·Π²ΡΠ°ΡΠ°Π΅ΠΌΡΠ΅ Π·Π½Π°ΡΠ΅Π½ΠΈΡ ΠΏΠ΅ΡΠ²ΠΈΡΠ½ΡΡ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠΉ | |
707 | /// ΠΈΠ³Π½ΠΎΡΠΈΡΡΡΡΡΡ. |
|
707 | /// ΠΈΠ³Π½ΠΎΡΠΈΡΡΡΡΡΡ. | |
708 | /// </summary> |
|
708 | /// </summary> | |
709 | /// <param name="promises">ΠΠΎΠ»Π»Π΅ΠΊΡΠΈΡ ΠΏΠ΅ΡΠ²ΠΈΡΠ½ΡΡ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠΉ, ΠΊΠΎΡΠΎΡΡΠ΅ Π±ΡΠ΄ΡΡ ΠΎΠ±ΡΠ΅Π΄Π΅Π½Π΅Π½Ρ Π² ΠΎΠ΄Π½ΠΎ.</param> |
|
709 | /// <param name="promises">ΠΠΎΠ»Π»Π΅ΠΊΡΠΈΡ ΠΏΠ΅ΡΠ²ΠΈΡΠ½ΡΡ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠΉ, ΠΊΠΎΡΠΎΡΡΠ΅ Π±ΡΠ΄ΡΡ ΠΎΠ±ΡΠ΅Π΄Π΅Π½Π΅Π½Ρ Π² ΠΎΠ΄Π½ΠΎ.</param> | |
710 | /// <returns>ΠΠΎΠ²ΠΎΠ΅ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅, ΠΎΠ±ΡΠ΅Π΄ΠΈΠ½ΡΡΡΠ΅Π΅ Π² ΡΠ΅Π±Π΅ ΠΏΠ΅ΡΠ΅Π΄Π°Π½Π½ΡΠ΅.</returns> |
|
710 | /// <returns>ΠΠΎΠ²ΠΎΠ΅ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅, ΠΎΠ±ΡΠ΅Π΄ΠΈΠ½ΡΡΡΠ΅Π΅ Π² ΡΠ΅Π±Π΅ ΠΏΠ΅ΡΠ΅Π΄Π°Π½Π½ΡΠ΅.</returns> | |
711 | /// <remarks> |
|
711 | /// <remarks> | |
712 | /// ΠΡΠ»ΠΈ Π² ΠΊΠΎΠ»Π»Π΅ΠΊΡΠΈΠΈ Π²ΡΡΡΠ΅ΡΠ°ΡΡΡΡ <c>null</c>, ΡΠΎ ΠΎΠ½ΠΈ Π²ΠΎΡΠΏΡΠΈΠ½ΠΈΠΌΠ°ΡΡΡΡ ΠΊΠ°ΠΊ Π²ΡΠΏΠΎΠ»Π½Π΅Π½Π½ΡΠ΅ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ. |
|
712 | /// ΠΡΠ»ΠΈ Π² ΠΊΠΎΠ»Π»Π΅ΠΊΡΠΈΠΈ Π²ΡΡΡΠ΅ΡΠ°ΡΡΡΡ <c>null</c>, ΡΠΎ ΠΎΠ½ΠΈ Π²ΠΎΡΠΏΡΠΈΠ½ΠΈΠΌΠ°ΡΡΡΡ ΠΊΠ°ΠΊ Π²ΡΠΏΠΎΠ»Π½Π΅Π½Π½ΡΠ΅ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΡ. | |
713 | /// </remarks> |
|
713 | /// </remarks> | |
714 | public static IPromise CreateComposite(ICollection<IPromise> promises) { |
|
714 | public static IPromise CreateComposite(ICollection<IPromise> promises) { | |
715 | if (promises == null) |
|
715 | if (promises == null) | |
716 | throw new ArgumentNullException(); |
|
716 | throw new ArgumentNullException(); | |
717 | if (promises.Count == 0) |
|
717 | if (promises.Count == 0) | |
718 | return Promise<object>.ResultToPromise(null); |
|
718 | return Promise<object>.ResultToPromise(null); | |
719 |
|
719 | |||
720 | int countdown = promises.Count; |
|
720 | int countdown = promises.Count; | |
721 |
|
721 | |||
722 | var result = new Promise<object>(); |
|
722 | var result = new Promise<object>(); | |
723 |
|
723 | |||
724 | foreach (var d in promises) { |
|
724 | foreach (var d in promises) { | |
725 | if (d == null) { |
|
725 | if (d == null) { | |
726 | if (Interlocked.Decrement(ref countdown) == 0) |
|
726 | if (Interlocked.Decrement(ref countdown) == 0) | |
727 | result.Resolve(null); |
|
727 | result.Resolve(null); | |
728 | } else { |
|
728 | } else { | |
729 | d.Then(() => { |
|
729 | d.Then(() => { | |
730 | if (Interlocked.Decrement(ref countdown) == 0) |
|
730 | if (Interlocked.Decrement(ref countdown) == 0) | |
731 | result.Resolve(null); |
|
731 | result.Resolve(null); | |
732 | }); |
|
732 | }); | |
733 | } |
|
733 | } | |
734 | } |
|
734 | } | |
735 |
|
735 | |||
736 | result.Cancelled(() => { |
|
736 | result.Cancelled(() => { | |
737 | foreach (var d in promises) |
|
737 | foreach (var d in promises) | |
738 | if (d != null && d.IsExclusive) |
|
738 | if (d != null && d.IsExclusive) | |
739 | d.Cancel(); |
|
739 | d.Cancel(); | |
740 | }); |
|
740 | }); | |
741 |
|
741 | |||
742 | return result; |
|
742 | return result; | |
743 | } |
|
743 | } | |
744 |
|
744 | |||
745 | public static Promise<T> ResultToPromise(T result) { |
|
745 | public static Promise<T> ResultToPromise(T result) { | |
746 | var p = new Promise<T>(); |
|
746 | var p = new Promise<T>(); | |
747 | p.Resolve(result); |
|
747 | p.Resolve(result); | |
748 | return p; |
|
748 | return p; | |
749 | } |
|
749 | } | |
750 |
|
750 | |||
751 | public static Promise<T> ExceptionToPromise(Exception error) { |
|
751 | public static Promise<T> ExceptionToPromise(Exception error) { | |
752 | if (error == null) |
|
752 | if (error == null) | |
753 | throw new ArgumentNullException(); |
|
753 | throw new ArgumentNullException(); | |
754 |
|
754 | |||
755 | var p = new Promise<T>(); |
|
755 | var p = new Promise<T>(); | |
756 | p.Reject(error); |
|
756 | p.Reject(error); | |
757 | return p; |
|
757 | return p; | |
758 | } |
|
758 | } | |
759 |
|
759 | |||
760 | #region IPromiseBase explicit implementation |
|
760 | #region IPromiseBase explicit implementation | |
761 |
|
761 | |||
762 | IPromise IPromise.Then(Action success, ErrorHandler error, Action cancel) { |
|
762 | IPromise IPromise.Then(Action success, ErrorHandler error, Action cancel) { | |
763 | return Then( |
|
763 | return Then( | |
764 | success != null ? new ResultHandler<T>(x => success()) : null, |
|
764 | success != null ? new ResultHandler<T>(x => success()) : null, | |
765 | error != null ? new ErrorHandler<T>(e => { |
|
765 | error != null ? new ErrorHandler<T>(e => { | |
766 | error(e); |
|
766 | error(e); | |
767 | return default(T); |
|
767 | return default(T); | |
768 | }) : null, |
|
768 | }) : null, | |
769 | cancel |
|
769 | cancel | |
770 | ); |
|
770 | ); | |
771 | } |
|
771 | } | |
772 |
|
772 | |||
773 | IPromise IPromise.Then(Action success, ErrorHandler error) { |
|
773 | IPromise IPromise.Then(Action success, ErrorHandler error) { | |
774 | return Then( |
|
774 | return Then( | |
775 | success != null ? new ResultHandler<T>(x => success()) : null, |
|
775 | success != null ? new ResultHandler<T>(x => success()) : null, | |
776 | error != null ? new ErrorHandler<T>(e => { |
|
776 | error != null ? new ErrorHandler<T>(e => { | |
777 | error(e); |
|
777 | error(e); | |
778 | return default(T); |
|
778 | return default(T); | |
779 | }) : null |
|
779 | }) : null | |
780 | ); |
|
780 | ); | |
781 | } |
|
781 | } | |
782 |
|
782 | |||
783 | IPromise IPromise.Then(Action success) { |
|
783 | IPromise IPromise.Then(Action success) { | |
784 | Safe.ArgumentNotNull(success, "success"); |
|
784 | Safe.ArgumentNotNull(success, "success"); | |
785 | return Then(x => success()); |
|
785 | return Then(x => success()); | |
786 | } |
|
786 | } | |
787 |
|
787 | |||
788 | IPromise IPromise.Chain(Func<IPromise> chained, ErrorHandler<IPromise> error, Action cancel) { |
|
788 | IPromise IPromise.Chain(Func<IPromise> chained, ErrorHandler<IPromise> error, Action cancel) { | |
789 | return ChainNoResult(chained, error, cancel); |
|
789 | return ChainNoResult(chained, error, cancel); | |
790 | } |
|
790 | } | |
791 |
|
791 | |||
792 | IPromise ChainNoResult(Func<IPromise> chained, ErrorHandler<IPromise> error, Action cancel) { |
|
792 | IPromise ChainNoResult(Func<IPromise> chained, ErrorHandler<IPromise> error, Action cancel) { | |
793 | Safe.ArgumentNotNull(chained, "chained"); |
|
793 | Safe.ArgumentNotNull(chained, "chained"); | |
794 |
|
794 | |||
795 | var medium = new Promise<object>(this, true); |
|
795 | var medium = new Promise<object>(this, true); | |
796 |
|
796 | |||
797 | ResultHandler<T> resultHandler = delegate(T result) { |
|
797 | ResultHandler<T> resultHandler = delegate(T result) { | |
798 | if (medium.IsCancelled) |
|
798 | if (medium.IsCancelled) | |
799 | return; |
|
799 | return; | |
800 |
|
800 | |||
801 | var promise = chained(); |
|
801 | var promise = chained(); | |
802 |
|
802 | |||
803 | promise.Last( |
|
803 | promise.Last( | |
804 | medium.Resolve, |
|
804 | medium.Resolve, | |
805 | medium.Reject, |
|
805 | medium.Reject, | |
806 | () => medium.Reject(new OperationCanceledException()) // Π²Π½Π΅ΡΠ½ΡΡ ΠΎΡΠΌΠ΅Π½Π° ΡΠ²ΡΠ·Π°Π½Π½ΠΎΠΉ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ ΡΠ°ΡΡΠΌΠ°ΡΡΠΈΠ²Π°Π΅ΡΡΡ ΠΊΠ°ΠΊ ΠΎΡΠΈΠ±ΠΊΠ° |
|
806 | () => medium.Reject(new OperationCanceledException()) // Π²Π½Π΅ΡΠ½ΡΡ ΠΎΡΠΌΠ΅Π½Π° ΡΠ²ΡΠ·Π°Π½Π½ΠΎΠΉ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ ΡΠ°ΡΡΠΌΠ°ΡΡΠΈΠ²Π°Π΅ΡΡΡ ΠΊΠ°ΠΊ ΠΎΡΠΈΠ±ΠΊΠ° | |
807 | ); |
|
807 | ); | |
808 |
|
808 | |||
809 | // notify chained operation that it's not needed anymore |
|
809 | // notify chained operation that it's not needed anymore | |
810 | // ΠΏΠΎΡΡΠ΄ΠΎΠΊ Π²ΡΠ·ΠΎΠ²Π° Then, Cancelled Π²Π°ΠΆΠ΅Π½, ΠΏΠΎΡΠΊΠΎΠ»ΡΠΊΡ ΠΎΡ ΡΡΠΎΠ³ΠΎ |
|
810 | // ΠΏΠΎΡΡΠ΄ΠΎΠΊ Π²ΡΠ·ΠΎΠ²Π° Then, Cancelled Π²Π°ΠΆΠ΅Π½, ΠΏΠΎΡΠΊΠΎΠ»ΡΠΊΡ ΠΎΡ ΡΡΠΎΠ³ΠΎ | |
811 | // Π·Π°Π²ΠΈΡΠΈΡ IsExclusive |
|
811 | // Π·Π°Π²ΠΈΡΠΈΡ IsExclusive | |
812 | medium.Cancelled(() => { |
|
812 | medium.Cancelled(() => { | |
813 | if (promise.IsExclusive) |
|
813 | if (promise.IsExclusive) | |
814 | promise.Cancel(); |
|
814 | promise.Cancel(); | |
815 | }); |
|
815 | }); | |
816 | }; |
|
816 | }; | |
817 |
|
817 | |||
818 | ErrorHandler<T> errorHandler; |
|
818 | ErrorHandler<T> errorHandler; | |
819 |
|
819 | |||
820 | if (error != null) |
|
820 | if (error != null) | |
821 | errorHandler = delegate(Exception e) { |
|
821 | errorHandler = delegate(Exception e) { | |
822 | try { |
|
822 | try { | |
823 | var promise = error(e); |
|
823 | var promise = error(e); | |
824 |
|
824 | |||
825 | promise.Last( |
|
825 | promise.Last( | |
826 | medium.Resolve, |
|
826 | medium.Resolve, | |
827 | medium.Reject, |
|
827 | medium.Reject, | |
828 | () => medium.Reject(new OperationCanceledException()) // Π²Π½Π΅ΡΠ½ΡΡ ΠΎΡΠΌΠ΅Π½Π° ΡΠ²ΡΠ·Π°Π½Π½ΠΎΠΉ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ ΡΠ°ΡΡΠΌΠ°ΡΡΠΈΠ²Π°Π΅ΡΡΡ ΠΊΠ°ΠΊ ΠΎΡΠΈΠ±ΠΊΠ° |
|
828 | () => medium.Reject(new OperationCanceledException()) // Π²Π½Π΅ΡΠ½ΡΡ ΠΎΡΠΌΠ΅Π½Π° ΡΠ²ΡΠ·Π°Π½Π½ΠΎΠΉ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ ΡΠ°ΡΡΠΌΠ°ΡΡΠΈΠ²Π°Π΅ΡΡΡ ΠΊΠ°ΠΊ ΠΎΡΠΈΠ±ΠΊΠ° | |
829 | ); |
|
829 | ); | |
830 |
|
830 | |||
831 | // notify chained operation that it's not needed anymore |
|
831 | // notify chained operation that it's not needed anymore | |
832 | // ΠΏΠΎΡΡΠ΄ΠΎΠΊ Π²ΡΠ·ΠΎΠ²Π° Then, Cancelled Π²Π°ΠΆΠ΅Π½, ΠΏΠΎΡΠΊΠΎΠ»ΡΠΊΡ ΠΎΡ ΡΡΠΎΠ³ΠΎ |
|
832 | // ΠΏΠΎΡΡΠ΄ΠΎΠΊ Π²ΡΠ·ΠΎΠ²Π° Then, Cancelled Π²Π°ΠΆΠ΅Π½, ΠΏΠΎΡΠΊΠΎΠ»ΡΠΊΡ ΠΎΡ ΡΡΠΎΠ³ΠΎ | |
833 | // Π·Π°Π²ΠΈΡΠΈΡ IsExclusive |
|
833 | // Π·Π°Π²ΠΈΡΠΈΡ IsExclusive | |
834 | medium.Cancelled(() => { |
|
834 | medium.Cancelled(() => { | |
835 | if (promise.IsExclusive) |
|
835 | if (promise.IsExclusive) | |
836 | promise.Cancel(); |
|
836 | promise.Cancel(); | |
837 | }); |
|
837 | }); | |
838 | } catch (Exception e2) { |
|
838 | } catch (Exception e2) { | |
839 | medium.Reject(e2); |
|
839 | medium.Reject(e2); | |
840 | } |
|
840 | } | |
841 | return default(T); |
|
841 | return default(T); | |
842 | }; |
|
842 | }; | |
843 | else |
|
843 | else | |
844 | errorHandler = err => { |
|
844 | errorHandler = err => { | |
845 | medium.Reject(err); |
|
845 | medium.Reject(err); | |
846 | return default(T); |
|
846 | return default(T); | |
847 | }; |
|
847 | }; | |
848 |
|
848 | |||
849 |
|
849 | |||
850 | Action cancelHandler; |
|
850 | Action cancelHandler; | |
851 | if (cancel != null) |
|
851 | if (cancel != null) | |
852 | cancelHandler = () => { |
|
852 | cancelHandler = () => { | |
853 | if (cancel != null) |
|
853 | if (cancel != null) | |
854 | cancel(); |
|
854 | cancel(); | |
855 | medium.Cancel(); |
|
855 | medium.Cancel(); | |
856 | }; |
|
856 | }; | |
857 | else |
|
857 | else | |
858 | cancelHandler = medium.Cancel; |
|
858 | cancelHandler = medium.Cancel; | |
859 |
|
859 | |||
860 | AddHandler( |
|
860 | AddHandler( | |
861 | resultHandler, |
|
861 | resultHandler, | |
862 | errorHandler, |
|
862 | errorHandler, | |
863 | cancelHandler, |
|
863 | cancelHandler, | |
864 | null |
|
864 | null | |
865 | ); |
|
865 | ); | |
866 |
|
866 | |||
867 | return medium; |
|
867 | return medium; | |
868 | } |
|
868 | } | |
869 | IPromise IPromise.Chain(Func<IPromise> chained, ErrorHandler<IPromise> error) { |
|
869 | IPromise IPromise.Chain(Func<IPromise> chained, ErrorHandler<IPromise> error) { | |
870 | return ChainNoResult(chained, error, null); |
|
870 | return ChainNoResult(chained, error, null); | |
871 | } |
|
871 | } | |
872 | IPromise IPromise.Chain(Func<IPromise> chained) { |
|
872 | IPromise IPromise.Chain(Func<IPromise> chained) { | |
873 | return ChainNoResult(chained, null, null); |
|
873 | return ChainNoResult(chained, null, null); | |
874 | } |
|
874 | } | |
875 |
|
875 | |||
876 |
|
876 | |||
877 | void IPromise.Last(Action success, ErrorHandler error, Action cancel) { |
|
877 | void IPromise.Last(Action success, ErrorHandler error, Action cancel) { | |
878 | Last(x => success(), error, cancel); |
|
878 | Last(x => success(), error, cancel); | |
879 | } |
|
879 | } | |
880 |
|
880 | |||
881 | void IPromise.Last(Action success, ErrorHandler error) { |
|
881 | void IPromise.Last(Action success, ErrorHandler error) { | |
882 | Last(x => success(), error, null); |
|
882 | Last(x => success(), error, null); | |
883 | } |
|
883 | } | |
884 |
|
884 | |||
885 | void IPromise.Last(Action success) { |
|
885 | void IPromise.Last(Action success) { | |
886 | Last(x => success(), null, null); |
|
886 | Last(x => success(), null, null); | |
887 | } |
|
887 | } | |
888 |
|
888 | |||
889 | IPromise IPromise.Error(ErrorHandler error) { |
|
889 | IPromise IPromise.Error(ErrorHandler error) { | |
890 | return Error(error); |
|
890 | return Error(error); | |
891 | } |
|
891 | } | |
892 |
|
892 | |||
893 | IPromise IPromise.Anyway(Action handler) { |
|
893 | IPromise IPromise.Anyway(Action handler) { | |
894 | return Anyway(handler); |
|
894 | return Anyway(handler); | |
895 | } |
|
895 | } | |
896 |
|
896 | |||
897 | IPromise IPromise.Cancelled(Action handler) { |
|
897 | IPromise IPromise.Cancelled(Action handler) { | |
898 | return Cancelled(handler); |
|
898 | return Cancelled(handler); | |
899 | } |
|
899 | } | |
900 |
|
900 | |||
901 | void IPromise.Join() { |
|
901 | void IPromise.Join() { | |
902 | Join(); |
|
902 | Join(); | |
903 | } |
|
903 | } | |
904 |
|
904 | |||
905 | void IPromise.Join(int timeout) { |
|
905 | void IPromise.Join(int timeout) { | |
906 | Join(timeout); |
|
906 | Join(timeout); | |
907 | } |
|
907 | } | |
908 |
|
908 | |||
909 | #endregion |
|
909 | #endregion | |
910 |
|
910 | |||
911 |
|
911 | |||
912 |
|
912 | |||
913 | } |
|
913 | } | |
914 | } |
|
914 | } |
General Comments 0
You need to be logged in to leave comments.
Login now