Mercurial > pub > ImplabNet
annotate Implab/IPromise.cs @ 145:706fccb85524 v2
RC: cancellation support for promises + tests
author | cin |
---|---|
date | Sun, 08 Mar 2015 02:52:27 +0300 |
parents | 8c0b95069066 |
children | ec91a6dfa5b3 |
rev | line source |
---|---|
7 | 1 using System; |
2 using System.Collections.Generic; | |
3 using System.Linq; | |
4 using System.Text; | |
5 | |
66 | 6 namespace Implab { |
7 public interface IPromise: ICancellable { | |
26 | 8 |
66 | 9 /// <summary> |
10 /// Тип результата, получаемого через данное обещание. | |
11 /// </summary> | |
12 Type PromiseType { get; } | |
25 | 13 |
74 | 14 /// <summary> |
99 | 15 /// Обещание является выполненым, либо успешно, либо с ошибкой, либо отменено. |
74 | 16 /// </summary> |
66 | 17 bool IsResolved { get; } |
18 | |
74 | 19 /// <summary> |
20 /// Обещание было отменено. | |
21 /// </summary> | |
66 | 22 bool IsCancelled { get; } |
25 | 23 |
119
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
24 /// <summary> |
138
f75cfa58e3d4
added ICancellable.Cancel(Exception) to allow specify the reason of cancellation
cin
parents:
119
diff
changeset
|
25 /// Исключение возникшее в результате выполнения обещания, либо причина отмены. |
f75cfa58e3d4
added ICancellable.Cancel(Exception) to allow specify the reason of cancellation
cin
parents:
119
diff
changeset
|
26 /// </summary> |
f75cfa58e3d4
added ICancellable.Cancel(Exception) to allow specify the reason of cancellation
cin
parents:
119
diff
changeset
|
27 Exception Error { get; } |
f75cfa58e3d4
added ICancellable.Cancel(Exception) to allow specify the reason of cancellation
cin
parents:
119
diff
changeset
|
28 |
f75cfa58e3d4
added ICancellable.Cancel(Exception) to allow specify the reason of cancellation
cin
parents:
119
diff
changeset
|
29 /// <summary> |
119
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
30 /// Creates a new promise dependend on the current one and resolved on |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
31 /// executing the specified handlers. |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
32 /// </summary> |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
33 /// <param name="success">The handler called on the successful promise completion.</param> |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
34 /// <param name="error">The handler is called if an error while completing the promise occurred.</param> |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
35 /// <param name="cancel">The handler is called in case of promise cancellation.</param> |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
36 /// <returns>The newly created dependant promise.</returns> |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
37 /// <remarks> |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
38 /// <para> |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
39 /// If the success handler is specified the dependend promise will be resolved after the handler is |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
40 /// executed and the dependent promise will be linked to the current one, i.e. the cancellation |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
41 /// of the dependent property will lead to the cancellation of the current promise. If the |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
42 /// success handler isn't specified the dependent promise will not be linked to and |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
43 /// will not be resolved after the successfull resolution of the current one. |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
44 /// </para> |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
45 /// <para> |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
46 /// When the error handler is specified, the exception raised during the current promise completion |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
47 /// will be passed to it as the parameter. If the error handler returns without raising an |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
48 /// exception then the dependant promise will be resolved successfully, otherwise the exception |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
49 /// raised by the handler will be transmitted to the dependent promise. If the handler wants |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
50 /// to passthrough the original exception it needs to wrap the exception with |
138
f75cfa58e3d4
added ICancellable.Cancel(Exception) to allow specify the reason of cancellation
cin
parents:
119
diff
changeset
|
51 /// the <see cref="PromiseTransientException"/>. The handler may raise <see cref="OperationCanceledException"/> |
f75cfa58e3d4
added ICancellable.Cancel(Exception) to allow specify the reason of cancellation
cin
parents:
119
diff
changeset
|
52 /// to cancel the dependant promise, the innner exception specifies the reason why the promise |
f75cfa58e3d4
added ICancellable.Cancel(Exception) to allow specify the reason of cancellation
cin
parents:
119
diff
changeset
|
53 /// is canceled. |
119
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
54 /// </para> |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
55 /// <para> |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
56 /// If the cancelation handler is specified and the current promise is cancelled then the dependent |
138
f75cfa58e3d4
added ICancellable.Cancel(Exception) to allow specify the reason of cancellation
cin
parents:
119
diff
changeset
|
57 /// promise will be resolved after the handler is executed. If the cancelation handler raises the |
119
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
58 /// exception it will be passed to the dependent promise. |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
59 /// </para> |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
60 /// </remarks> |
144 | 61 /* IPromise Then(Action success, Action<Exception> error, Action<Exception> cancel); |
101 | 62 IPromise Then(Action success, Action<Exception> error); |
66 | 63 IPromise Then(Action success); |
75 | 64 |
138
f75cfa58e3d4
added ICancellable.Cancel(Exception) to allow specify the reason of cancellation
cin
parents:
119
diff
changeset
|
65 IPromise Chain(Func<IPromise> chained, Func<Exception, IPromise> error, Func<Exception, IPromise> cancel); |
101 | 66 IPromise Chain(Func<IPromise> chained, Func<Exception, IPromise> error); |
144 | 67 IPromise Chain(Func<IPromise> chained);*/ |
96 | 68 |
75 | 69 /// <summary> |
119
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
70 /// Adds specified listeners to the current promise. |
75 | 71 /// </summary> |
119
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
72 /// <param name="success">The handler called on the successful promise completion.</param> |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
73 /// <param name="error">The handler is called if an error while completing the promise occurred.</param> |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
74 /// <param name="cancel">The handler is called in case of promise cancellation.</param> |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
75 /// <returns>The current promise.</returns> |
138
f75cfa58e3d4
added ICancellable.Cancel(Exception) to allow specify the reason of cancellation
cin
parents:
119
diff
changeset
|
76 IPromise On(Action success, Action<Exception> error, Action<Exception> cancel); |
119
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
77 IPromise On(Action success, Action<Exception> error); |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
78 IPromise On(Action success); |
75 | 79 |
74 | 80 /// <summary> |
119
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
81 /// Adds specified listeners to the current promise. |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
82 /// </summary> |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
83 /// <param name="handler">The handler called on the specified events.</param> |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
84 /// <param name = "events">The combination of flags denoting the events for which the |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
85 /// handler shoud be called.</param> |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
86 /// <returns>The current promise.</returns> |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
87 IPromise On(Action handler, PromiseEventType events); |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
88 |
2573b562e328
Promises rewritten, added improved version of AsyncQueue
cin
parents:
104
diff
changeset
|
89 /// <summary> |
74 | 90 /// Преобразует результат обещания к заданному типу и возвращает новое обещание. |
91 /// </summary> | |
66 | 92 IPromise<T> Cast<T>(); |
26 | 93 |
74 | 94 /// <summary> |
95 /// Синхронизирует текущий поток с обещанием. | |
96 /// </summary> | |
66 | 97 void Join(); |
74 | 98 /// <summary> |
99 /// Синхронизирует текущий поток с обещанием. | |
100 /// </summary> | |
101 /// <param name="timeout">Время ожидания, по его истечению возникнет исключение.</param> | |
102 /// <exception cref="TimeoutException">Превышено время ожидания.</exception> | |
66 | 103 void Join(int timeout); |
7 | 104 |
105 } | |
106 } |