##// END OF EJS Templates
DRAFT: refactoring, adding cancelation token
cin -
r143:16f926ee499d v2
parent child
Show More
@@ -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 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 289 public Exception Error {
302 290 get {
303 291 return m_error;
@@ -4,7 +4,7 namespace Implab {
4 4 /// <summary>
5 5 /// Deferred result, usually used by asynchronous services as the service part of the promise.
6 6 /// </summary>
7 public interface IDeferred : ICancellable {
7 public interface IDeferred : ICancelationToken {
8 8
9 9 void Resolve();
10 10
@@ -1,7 +1,7
1 1 using System;
2 2
3 3 namespace Implab {
4 public interface IDeferred<T> : ICancellable {
4 public interface IDeferred<T> : ICancelationToken {
5 5 void Resolve(T value);
6 6
7 7 void Reject(Exception error);
@@ -7,6 +7,8
7 7 <OutputType>Library</OutputType>
8 8 <RootNamespace>Implab</RootNamespace>
9 9 <AssemblyName>Implab</AssemblyName>
10 <ProductVersion>8.0.30703</ProductVersion>
11 <SchemaVersion>2.0</SchemaVersion>
10 12 </PropertyGroup>
11 13 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
12 14 <DebugSymbols>true</DebugSymbols>
@@ -156,6 +158,7
156 158 <Compile Include="Diagnostics\ILogWriter.cs" />
157 159 <Compile Include="Diagnostics\ListenerBase.cs" />
158 160 <Compile Include="Parallels\BlockingQueue.cs" />
161 <Compile Include="ICancelationToken.cs" />
159 162 </ItemGroup>
160 163 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
161 164 <ItemGroup />
General Comments 0
You need to be logged in to leave comments. Login now