TaskServices.Default.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the Apache 2.0 License.
  3. // See the LICENSE file in the project root for more information.
  4. #if !NO_TPL
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. #if HAS_TPL46
  8. namespace System.Reactive.PlatformServices
  9. {
  10. //
  11. // WARNING: This code is kept *identically* in two places. One copy is kept in System.Reactive.Core for non-PLIB platforms.
  12. // Another copy is kept in System.Reactive.PlatformServices to enlighten the default lowest common denominator
  13. // behavior of Rx for PLIB when used on a more capable platform.
  14. //
  15. internal class DefaultTaskServices/*Impl*/ : ITaskServices
  16. {
  17. public bool TrySetCanceled<T>(TaskCompletionSource<T> tcs, CancellationToken token)
  18. {
  19. return tcs.TrySetCanceled(token);
  20. }
  21. }
  22. }
  23. #else
  24. namespace System.Reactive.PlatformServices
  25. {
  26. internal class DefaultTaskServices : ITaskServices
  27. {
  28. public bool TrySetCanceled<T>(TaskCompletionSource<T> tcs, CancellationToken token)
  29. {
  30. return tcs.TrySetCanceled();
  31. }
  32. }
  33. }
  34. #endif
  35. #endif