// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. #if !NO_TPL using System.Threading; namespace System.Reactive.Disposables { /// /// Represents a disposable resource that has an associated that will be set to the cancellation requested state upon disposal. /// public sealed class CancellationDisposable : ICancelable { private readonly CancellationTokenSource _cts; /// /// Initializes a new instance of the class that uses an existing . /// /// used for cancellation. /// is null. public CancellationDisposable(CancellationTokenSource cts) { if (cts == null) throw new ArgumentNullException("cts"); _cts = cts; } /// /// Initializes a new instance of the class that uses a new . /// public CancellationDisposable() : this(new CancellationTokenSource()) { } /// /// Gets the used by this CancellationDisposable. /// public CancellationToken Token { get { return _cts.Token; } } /// /// Cancels the underlying . /// public void Dispose() { _cts.Cancel(); } /// /// Gets a value that indicates whether the object is disposed. /// public bool IsDisposed { get { return _cts.IsCancellationRequested; } } } } #endif