| @@ -0,0 +1,31 | |||||
|
|
1 | using System; | |||
|
|
2 | using System.Collections.Generic; | |||
|
|
3 | using System.Linq; | |||
|
|
4 | using System.Text; | |||
|
|
5 | ||||
|
|
6 | namespace Implab | |||
|
|
7 | { | |||
|
|
8 | public interface IPromise<T>: IPromise | |||
|
|
9 | { | |||
|
|
10 | ||||
|
|
11 | new T Join(); | |||
|
|
12 | new T Join(int timeout); | |||
|
|
13 | ||||
|
|
14 | IPromise<T> Then(ResultHandler<T> success, ErrorHandler error); | |||
|
|
15 | IPromise<T> Then(ResultHandler<T> success, ErrorHandler<T> error); | |||
|
|
16 | IPromise<T> Then(ResultHandler<T> success); | |||
|
|
17 | new IPromise<T> Error(ErrorHandler error); | |||
|
|
18 | IPromise<T> Error(ErrorHandler<T> error); | |||
|
|
19 | ||||
|
|
20 | IPromise<T2> Map<T2>(ResultMapper<T,T2> mapper, ErrorHandler error); | |||
|
|
21 | IPromise<T2> Map<T2>(ResultMapper<T, T2> mapper); | |||
|
|
22 | ||||
|
|
23 | IPromise<T2> Chain<T2>(ChainedOperation<T, T2> chained, ErrorHandler error); | |||
|
|
24 | IPromise<T2> Chain<T2>(ChainedOperation<T, T2> chained); | |||
|
|
25 | ||||
|
|
26 | new IPromise<T> Cancelled(Action handler); | |||
|
|
27 | new IPromise<T> Finally(Action handler); | |||
|
|
28 | new IPromise<T> Anyway(Action handler); | |||
|
|
29 | ||||
|
|
30 | } | |||
|
|
31 | } | |||
| @@ -16,8 +16,8 namespace Implab.Diagnostics.Interactive | |||||
| 16 | SynchronizationContext m_syncGuiThread; |
|
16 | SynchronizationContext m_syncGuiThread; | |
| 17 | readonly Promise<object> m_guiStarted = new Promise<object>(); |
|
17 | readonly Promise<object> m_guiStarted = new Promise<object>(); | |
| 18 |
|
18 | |||
| 19 |
readonly IPromise |
|
19 | readonly IPromise m_guiFinished; | |
| 20 |
readonly IPromise |
|
20 | readonly IPromise m_workerFinished = new Promise<object>(); | |
| 21 |
|
21 | |||
| 22 | readonly MTQueue<TraceViewItem> m_queue = new MTQueue<TraceViewItem>(); |
|
22 | readonly MTQueue<TraceViewItem> m_queue = new MTQueue<TraceViewItem>(); | |
| 23 | readonly AutoResetEvent m_queueEvent = new AutoResetEvent(false); |
|
23 | readonly AutoResetEvent m_queueEvent = new AutoResetEvent(false); | |
| @@ -211,7 +211,7 namespace Implab.Diagnostics { | |||||
| 211 | } |
|
211 | } | |
| 212 | } |
|
212 | } | |
| 213 |
|
213 | |||
| 214 |
public void BindLogicalOperationToPromise(IPromise |
|
214 | public void BindLogicalOperationToPromise(IPromise promise) { | |
| 215 | Safe.ArgumentNotNull(promise, "promise"); |
|
215 | Safe.ArgumentNotNull(promise, "promise"); | |
| 216 |
|
216 | |||
| 217 | var ctx = DetachLogicalOperation(); |
|
217 | var ctx = DetachLogicalOperation(); | |
| @@ -28,7 +28,7 namespace Implab.Diagnostics { | |||||
| 28 | } |
|
28 | } | |
| 29 |
|
29 | |||
| 30 | [Conditional("TRACE")] |
|
30 | [Conditional("TRACE")] | |
| 31 |
public static void BindLogicalOperationToPromise(IPromise |
|
31 | public static void BindLogicalOperationToPromise(IPromise promise) { | |
| 32 | TraceContext.Current.BindLogicalOperationToPromise(promise); |
|
32 | TraceContext.Current.BindLogicalOperationToPromise(promise); | |
| 33 | } |
|
33 | } | |
| 34 |
|
34 | |||
| @@ -3,29 +3,35 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 | { |
|
7 | public interface IPromise: ICancellable { | |
| 8 | public interface IPromise<T>: IPromiseBase |
|
8 | /// <summary> | |
| 9 | { |
|
9 | /// Check whereather the promise has no more than one dependent promise. | |
|
|
10 | /// </summary> | |||
|
|
11 | bool IsExclusive { | |||
|
|
12 | get; | |||
|
|
13 | } | |||
| 10 |
|
14 | |||
| 11 | new T Join(); |
|
15 | /// <summary> | |
| 12 | new T Join(int timeout); |
|
16 | /// Тип результата, получаемого через данное обещание. | |
|
|
17 | /// </summary> | |||
|
|
18 | Type PromiseType { get; } | |||
| 13 |
|
19 | |||
| 14 | IPromise<T> Then(ResultHandler<T> success, ErrorHandler error); |
|
20 | bool IsResolved { get; } | |
| 15 | IPromise<T> Then(ResultHandler<T> success, ErrorHandler<T> error); |
|
21 | ||
| 16 | IPromise<T> Then(ResultHandler<T> success); |
|
22 | bool IsCancelled { get; } | |
| 17 | new IPromise<T> Error(ErrorHandler error); |
|
|||
| 18 | IPromise<T> Error(ErrorHandler<T> error); |
|
|||
| 19 |
|
23 | |||
| 20 |
IPromise |
|
24 | IPromise Then(Action success,ErrorHandler error); | |
| 21 | IPromise<T2> Map<T2>(ResultMapper<T, T2> mapper); |
|
25 | IPromise Then(Action success); | |
|
|
26 | IPromise Error(ErrorHandler error); | |||
|
|
27 | IPromise Anyway(Action handler); | |||
|
|
28 | IPromise Finally(Action handler); | |||
|
|
29 | IPromise Cancelled(Action handler); | |||
| 22 |
|
30 | |||
| 23 | IPromise<T2> Chain<T2>(ChainedOperation<T, T2> chained, ErrorHandler error); |
|
31 | IPromise<T> Cast<T>(); | |
| 24 | IPromise<T2> Chain<T2>(ChainedOperation<T, T2> chained); |
|
|||
| 25 |
|
32 | |||
| 26 | new IPromise<T> Cancelled(Action handler); |
|
33 | void Join(); | |
| 27 | new IPromise<T> Finally(Action handler); |
|
34 | void Join(int timeout); | |
| 28 | new IPromise<T> Anyway(Action handler); |
|
|||
| 29 |
|
35 | |||
| 30 | } |
|
36 | } | |
| 31 | } |
|
37 | } | |
| @@ -51,8 +51,8 | |||||
| 51 | <Compile Include="ICancellable.cs" /> |
|
51 | <Compile Include="ICancellable.cs" /> | |
| 52 | <Compile Include="IProgressHandler.cs" /> |
|
52 | <Compile Include="IProgressHandler.cs" /> | |
| 53 | <Compile Include="IProgressNotifier.cs" /> |
|
53 | <Compile Include="IProgressNotifier.cs" /> | |
|
|
54 | <Compile Include="IPromiseT.cs" /> | |||
| 54 | <Compile Include="IPromise.cs" /> |
|
55 | <Compile Include="IPromise.cs" /> | |
| 55 | <Compile Include="IPromiseBase.cs" /> |
|
|||
| 56 | <Compile Include="IServiceLocator.cs" /> |
|
56 | <Compile Include="IServiceLocator.cs" /> | |
| 57 | <Compile Include="ITaskController.cs" /> |
|
57 | <Compile Include="ITaskController.cs" /> | |
| 58 | <Compile Include="JSON\JSONElementContext.cs" /> |
|
58 | <Compile Include="JSON\JSONElementContext.cs" /> | |
| @@ -48,7 +48,7 namespace Implab.Parallels { | |||||
| 48 | } |
|
48 | } | |
| 49 |
|
49 | |||
| 50 |
|
50 | |||
| 51 |
public static IPromise |
|
51 | public static IPromise InvokeNewThread(Action func) { | |
| 52 | var p = new Promise<object>(); |
|
52 | var p = new Promise<object>(); | |
| 53 |
|
53 | |||
| 54 | var caller = TraceContext.Snapshot(); |
|
54 | var caller = TraceContext.Snapshot(); | |
| @@ -99,7 +99,7 namespace Implab { | |||||
| 99 | m_cancellable = true; |
|
99 | m_cancellable = true; | |
| 100 | } |
|
100 | } | |
| 101 |
|
101 | |||
| 102 |
public Promise(IPromise |
|
102 | public Promise(IPromise parent, bool cancellable) { | |
| 103 | m_cancellable = cancellable; |
|
103 | m_cancellable = cancellable; | |
| 104 | if (parent != null) |
|
104 | if (parent != null) | |
| 105 | AddHandler( |
|
105 | AddHandler( | |
| @@ -252,11 +252,11 namespace Implab { | |||||
| 252 | return medium; |
|
252 | return medium; | |
| 253 | } |
|
253 | } | |
| 254 |
|
254 | |||
| 255 |
public IPromise |
|
255 | public IPromise Then(Action success, ErrorHandler error) { | |
| 256 | return Then(x => success(), error); |
|
256 | return Then(x => success(), error); | |
| 257 | } |
|
257 | } | |
| 258 |
|
258 | |||
| 259 |
public IPromise |
|
259 | public IPromise Then(Action success) { | |
| 260 | return Then(x => success()); |
|
260 | return Then(x => success()); | |
| 261 | } |
|
261 | } | |
| 262 |
|
262 | |||
| @@ -682,7 +682,7 namespace Implab { | |||||
| 682 | /// <remarks> |
|
682 | /// <remarks> | |
| 683 | /// Если в коллекции встречаюься <c>null</c>, то они воспринимаются как выполненные обещания. |
|
683 | /// Если в коллекции встречаюься <c>null</c>, то они воспринимаются как выполненные обещания. | |
| 684 | /// </remarks> |
|
684 | /// </remarks> | |
| 685 |
public static IPromise |
|
685 | public static IPromise CreateComposite(ICollection<IPromise> promises) { | |
| 686 | if (promises == null) |
|
686 | if (promises == null) | |
| 687 | throw new ArgumentNullException(); |
|
687 | throw new ArgumentNullException(); | |
| 688 | if (promises.Count == 0) |
|
688 | if (promises.Count == 0) | |
| @@ -730,27 +730,27 namespace Implab { | |||||
| 730 |
|
730 | |||
| 731 | #region IPromiseBase explicit implementation |
|
731 | #region IPromiseBase explicit implementation | |
| 732 |
|
732 | |||
| 733 |
IPromise |
|
733 | IPromise IPromise.Error(ErrorHandler error) { | |
| 734 | return Error(error); |
|
734 | return Error(error); | |
| 735 | } |
|
735 | } | |
| 736 |
|
736 | |||
| 737 |
IPromise |
|
737 | IPromise IPromise.Anyway(Action handler) { | |
| 738 | return Anyway(handler); |
|
738 | return Anyway(handler); | |
| 739 | } |
|
739 | } | |
| 740 |
|
740 | |||
| 741 |
IPromise |
|
741 | IPromise IPromise.Finally(Action handler) { | |
| 742 | return Finally(handler); |
|
742 | return Finally(handler); | |
| 743 | } |
|
743 | } | |
| 744 |
|
744 | |||
| 745 |
IPromise |
|
745 | IPromise IPromise.Cancelled(Action handler) { | |
| 746 | return Cancelled(handler); |
|
746 | return Cancelled(handler); | |
| 747 | } |
|
747 | } | |
| 748 |
|
748 | |||
| 749 |
void IPromise |
|
749 | void IPromise.Join() { | |
| 750 | Join(); |
|
750 | Join(); | |
| 751 | } |
|
751 | } | |
| 752 |
|
752 | |||
| 753 |
void IPromise |
|
753 | void IPromise.Join(int timeout) { | |
| 754 | Join(timeout); |
|
754 | Join(timeout); | |
| 755 | } |
|
755 | } | |
| 756 |
|
756 | |||
| @@ -3,6 +3,7 using System.Collections.Generic; | |||||
| 3 | using System.Linq; |
|
3 | using System.Linq; | |
| 4 | using System.Text; |
|
4 | using System.Text; | |
| 5 | using System.Text.RegularExpressions; |
|
5 | using System.Text.RegularExpressions; | |
|
|
6 | using System.Diagnostics; | |||
| 6 |
|
7 | |||
| 7 | namespace Implab |
|
8 | namespace Implab | |
| 8 | { |
|
9 | { | |
| @@ -36,5 +37,30 namespace Implab | |||||
| 36 | if (disp != null) |
|
37 | if (disp != null) | |
| 37 | disp.Dispose(); |
|
38 | disp.Dispose(); | |
| 38 | } |
|
39 | } | |
|
|
40 | ||||
|
|
41 | [DebuggerStepThrough] | |||
|
|
42 | public static IPromise<T> GuargPromise<T>(Func<T> action) { | |||
|
|
43 | ArgumentNotNull(action, "action"); | |||
|
|
44 | ||||
|
|
45 | var p = new Promise<T>(); | |||
|
|
46 | try { | |||
|
|
47 | p.Resolve(action()); | |||
|
|
48 | } catch (Exception err) { | |||
|
|
49 | p.Reject(err); | |||
|
|
50 | } | |||
|
|
51 | ||||
|
|
52 | return p; | |||
|
|
53 | } | |||
|
|
54 | ||||
|
|
55 | [DebuggerStepThrough] | |||
|
|
56 | public static IPromise<T> GuardPromise<T>(Func<IPromise<T>> action) { | |||
|
|
57 | ArgumentNotNull(action, "action"); | |||
|
|
58 | ||||
|
|
59 | try { | |||
|
|
60 | return action(); | |||
|
|
61 | } catch (Exception err) { | |||
|
|
62 | return Promise<T>.ExceptionToPromise(err); | |||
| 39 | } |
|
63 | } | |
| 40 | } |
|
64 | } | |
|
|
65 | } | |||
|
|
66 | } | |||
| 1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now
