// original code from GitHub Reactive-Extensions/Rx.NET // some modified. // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. #if (NETFX_CORE || NET_4_6 || NET_STANDARD_2_0 || UNITY_WSA_10_0) using System; using System.Threading; namespace UniRx { /// /// 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