2
0

CancellationToken.cs 910 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #if !(NETFX_CORE || NET_4_6 || NET_STANDARD_2_0 || UNITY_WSA_10_0)
  2. using System;
  3. namespace UniRx
  4. {
  5. public struct CancellationToken
  6. {
  7. readonly ICancelable source;
  8. public static readonly CancellationToken Empty = new CancellationToken(null);
  9. /// <summary>Same as Empty.</summary>
  10. public static readonly CancellationToken None = new CancellationToken(null);
  11. public CancellationToken(ICancelable source)
  12. {
  13. this.source = source;
  14. }
  15. public bool IsCancellationRequested
  16. {
  17. get
  18. {
  19. return (source == null) ? false : source.IsDisposed;
  20. }
  21. }
  22. public void ThrowIfCancellationRequested()
  23. {
  24. if (IsCancellationRequested)
  25. {
  26. throw new OperationCanceledException();
  27. }
  28. }
  29. }
  30. }
  31. #endif