<PackageReference Include="System.Reactive" Version="7.0.0-preview.1" />

CancellationDisposable

using System.Runtime.CompilerServices; using System.Threading; namespace System.Reactive.Disposables { public sealed class CancellationDisposable : ICancelable, IDisposable { [System.Runtime.CompilerServices.Nullable(1)] private readonly CancellationTokenSource _cts; public CancellationToken Token => _cts.Token; public bool IsDisposed => _cts.IsCancellationRequested; [System.Runtime.CompilerServices.NullableContext(1)] public CancellationDisposable(CancellationTokenSource cts) { if (cts == null) throw new ArgumentNullException("cts"); _cts = cts; } public CancellationDisposable() : this(new CancellationTokenSource()) { } public void Dispose() { _cts.Cancel(); } } }