Disposables.cs 614 B

1234567891011121314151617181920212223
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT License.
  3. // See the LICENSE file in the project root for more information.
  4. using System.Threading;
  5. namespace System.Linq
  6. {
  7. internal sealed class CancellationTokenDisposable : IDisposable
  8. {
  9. private readonly CancellationTokenSource _cts = new();
  10. public CancellationToken Token => _cts.Token;
  11. public void Dispose()
  12. {
  13. if (!_cts.IsCancellationRequested)
  14. {
  15. _cts.Cancel();
  16. }
  17. }
  18. }
  19. }