| @@ -0,0 +1,36 | |||||
|
|
1 | using System; | |||
|
|
2 | ||||
|
|
3 | namespace Implab { | |||
|
|
4 | public interface ICancelationToken { | |||
|
|
5 | /// <summary> | |||
|
|
6 | /// Indicates wherther the cancellation was requested. | |||
|
|
7 | /// </summary> | |||
|
|
8 | bool IsCancelRequested { get ; } | |||
|
|
9 | ||||
|
|
10 | /// <summary> | |||
|
|
11 | /// The reason why the operation should be cancelled. | |||
|
|
12 | /// </summary> | |||
|
|
13 | Exception CancelReason { get ; } | |||
|
|
14 | ||||
|
|
15 | /// <summary> | |||
|
|
16 | /// Accepts if requested. | |||
|
|
17 | /// </summary> | |||
|
|
18 | /// <returns><c>true</c>, if if requested was accepted, <c>false</c> otherwise.</returns> | |||
|
|
19 | bool AcceptIfRequested(); | |||
|
|
20 | ||||
|
|
21 | /// <summary> | |||
|
|
22 | /// Sets the token to cancelled state. | |||
|
|
23 | /// </summary> | |||
|
|
24 | /// <param name="reason">The reason why the operation was cancelled.</param> | |||
|
|
25 | void SetCancelled(Exception reason); | |||
|
|
26 | ||||
|
|
27 | /// <summary> | |||
|
|
28 | /// Adds the listener for the cancellation request, is the cancellation was requested the <paramref name="handler"/> | |||
|
|
29 | /// is executed immediatelly. | |||
|
|
30 | /// </summary> | |||
|
|
31 | /// <param name="handler">The handler which will be executed if the cancel occurs.</param> | |||
|
|
32 | void CancellationRequested(Action<Exception> handler); | |||
|
|
33 | ||||
|
|
34 | } | |||
|
|
35 | } | |||
|
|
36 | ||||
| @@ -286,18 +286,6 namespace Implab { | |||||
| 286 |
|
286 | |||
| 287 | #endregion |
|
287 | #endregion | |
| 288 |
|
288 | |||
| 289 | #region ICancellable implementation |
|
|||
| 290 |
|
||||
| 291 | public void Cancel() { |
|
|||
| 292 | SetCancelled(null); |
|
|||
| 293 | } |
|
|||
| 294 |
|
||||
| 295 | public void Cancel(Exception reason) { |
|
|||
| 296 | SetCancelled(reason); |
|
|||
| 297 | } |
|
|||
| 298 |
|
||||
| 299 | #endregion |
|
|||
| 300 |
|
||||
| 301 | public Exception Error { |
|
289 | public Exception Error { | |
| 302 | get { |
|
290 | get { | |
| 303 | return m_error; |
|
291 | return m_error; | |
| @@ -4,7 +4,7 namespace Implab { | |||||
| 4 | /// <summary> |
|
4 | /// <summary> | |
| 5 | /// Deferred result, usually used by asynchronous services as the service part of the promise. |
|
5 | /// Deferred result, usually used by asynchronous services as the service part of the promise. | |
| 6 | /// </summary> |
|
6 | /// </summary> | |
| 7 |
public interface IDeferred : ICancel |
|
7 | public interface IDeferred : ICancelationToken { | |
| 8 |
|
8 | |||
| 9 | void Resolve(); |
|
9 | void Resolve(); | |
| 10 |
|
10 | |||
| @@ -1,7 +1,7 | |||||
| 1 | using System; |
|
1 | using System; | |
| 2 |
|
2 | |||
| 3 | namespace Implab { |
|
3 | namespace Implab { | |
| 4 |
public interface IDeferred<T> : ICancel |
|
4 | public interface IDeferred<T> : ICancelationToken { | |
| 5 | void Resolve(T value); |
|
5 | void Resolve(T value); | |
| 6 |
|
6 | |||
| 7 | void Reject(Exception error); |
|
7 | void Reject(Exception error); | |
| @@ -7,6 +7,8 | |||||
| 7 | <OutputType>Library</OutputType> |
|
7 | <OutputType>Library</OutputType> | |
| 8 | <RootNamespace>Implab</RootNamespace> |
|
8 | <RootNamespace>Implab</RootNamespace> | |
| 9 | <AssemblyName>Implab</AssemblyName> |
|
9 | <AssemblyName>Implab</AssemblyName> | |
|
|
10 | <ProductVersion>8.0.30703</ProductVersion> | |||
|
|
11 | <SchemaVersion>2.0</SchemaVersion> | |||
| 10 | </PropertyGroup> |
|
12 | </PropertyGroup> | |
| 11 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
|
13 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | |
| 12 | <DebugSymbols>true</DebugSymbols> |
|
14 | <DebugSymbols>true</DebugSymbols> | |
| @@ -156,6 +158,7 | |||||
| 156 | <Compile Include="Diagnostics\ILogWriter.cs" /> |
|
158 | <Compile Include="Diagnostics\ILogWriter.cs" /> | |
| 157 | <Compile Include="Diagnostics\ListenerBase.cs" /> |
|
159 | <Compile Include="Diagnostics\ListenerBase.cs" /> | |
| 158 | <Compile Include="Parallels\BlockingQueue.cs" /> |
|
160 | <Compile Include="Parallels\BlockingQueue.cs" /> | |
|
|
161 | <Compile Include="ICancelationToken.cs" /> | |||
| 159 | </ItemGroup> |
|
162 | </ItemGroup> | |
| 160 | <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> |
|
163 | <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> | |
| 161 | <ItemGroup /> |
|
164 | <ItemGroup /> | |
General Comments 0
You need to be logged in to leave comments.
Login now
