diff --git a/Implab/AbstractPromise.cs b/Implab/AbstractPromise.cs --- a/Implab/AbstractPromise.cs +++ b/Implab/AbstractPromise.cs @@ -286,18 +286,6 @@ namespace Implab { #endregion - #region ICancellable implementation - - public void Cancel() { - SetCancelled(null); - } - - public void Cancel(Exception reason) { - SetCancelled(reason); - } - - #endregion - public Exception Error { get { return m_error; diff --git a/Implab/ICancelationToken.cs b/Implab/ICancelationToken.cs new file mode 100644 --- /dev/null +++ b/Implab/ICancelationToken.cs @@ -0,0 +1,36 @@ +using System; + +namespace Implab { + public interface ICancelationToken { + /// + /// Indicates wherther the cancellation was requested. + /// + bool IsCancelRequested { get ; } + + /// + /// The reason why the operation should be cancelled. + /// + Exception CancelReason { get ; } + + /// + /// Accepts if requested. + /// + /// true, if if requested was accepted, false otherwise. + bool AcceptIfRequested(); + + /// + /// Sets the token to cancelled state. + /// + /// The reason why the operation was cancelled. + void SetCancelled(Exception reason); + + /// + /// Adds the listener for the cancellation request, is the cancellation was requested the + /// is executed immediatelly. + /// + /// The handler which will be executed if the cancel occurs. + void CancellationRequested(Action handler); + + } +} + diff --git a/Implab/IDeferred.cs b/Implab/IDeferred.cs --- a/Implab/IDeferred.cs +++ b/Implab/IDeferred.cs @@ -4,7 +4,7 @@ namespace Implab { /// /// Deferred result, usually used by asynchronous services as the service part of the promise. /// - public interface IDeferred : ICancellable { + public interface IDeferred : ICancelationToken { void Resolve(); diff --git a/Implab/IDeferredT.cs b/Implab/IDeferredT.cs --- a/Implab/IDeferredT.cs +++ b/Implab/IDeferredT.cs @@ -1,7 +1,7 @@ using System; namespace Implab { - public interface IDeferred : ICancellable { + public interface IDeferred : ICancelationToken { void Resolve(T value); void Reject(Exception error); diff --git a/Implab/Implab.csproj b/Implab/Implab.csproj --- a/Implab/Implab.csproj +++ b/Implab/Implab.csproj @@ -7,6 +7,8 @@ Library Implab Implab + 8.0.30703 + 2.0 true @@ -156,6 +158,7 @@ +