using System;
using System.Threading;
namespace ZeroLevel.Services.Async
{
///
/// A that may or may not also reference its own . Instances of this type should always be disposed.
///
public sealed class NormalizedCancellationToken : IDisposable
{
///
/// The , if any. If this is not null, then is _cts.Token.
///
private readonly CancellationTokenSource _cts;
///
/// The . If is not null, then this is _cts.Token.
///
private readonly CancellationToken _token;
///
/// Creates a normalized cancellation token that can never be canceled.
///
public NormalizedCancellationToken()
{
}
///
/// Creates a normalized cancellation token from a . is set to the property of .
///
/// The source for this token.
public NormalizedCancellationToken(CancellationTokenSource cts)
{
_cts = cts;
_token = cts.Token;
}
///
/// Creates a normalized cancellation token from a . is set to .
///
/// The source for this token.
public NormalizedCancellationToken(CancellationToken token)
{
_token = token;
}
///
/// Releases any resources used by this normalized cancellation token.
///
public void Dispose()
{
if (_cts != null)
_cts.Dispose();
}
///
/// Gets the for this normalized cancellation token.
///
public CancellationToken Token { get { return _token; } }
}
}