Bläddra i källkod

Simplify TPL46

Oren Novotny 8 år sedan
förälder
incheckning
15cc575c2c

+ 0 - 39
Rx.NET/Source/System.Reactive.Core/Reactive/Internal/TaskServices.Default.cs

@@ -1,39 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the Apache 2.0 License.
-// See the LICENSE file in the project root for more information. 
-
-#if !NO_TPL
-
-using System.Threading;
-using System.Threading.Tasks;
-
-#if HAS_TPL46
-namespace System.Reactive.PlatformServices
-{
-    //
-    // WARNING: This code is kept *identically* in two places. One copy is kept in System.Reactive.Core for non-PLIB platforms.
-    //          Another copy is kept in System.Reactive.PlatformServices to enlighten the default lowest common denominator
-    //          behavior of Rx for PLIB when used on a more capable platform.
-    //
-    internal class DefaultTaskServices/*Impl*/ : ITaskServices
-    {
-        public bool TrySetCanceled<T>(TaskCompletionSource<T> tcs, CancellationToken token)
-        {
-            return tcs.TrySetCanceled(token);
-        }
-    }
-}
-#else
-namespace System.Reactive.PlatformServices
-{
-    internal class DefaultTaskServices : ITaskServices
-    {
-        public bool TrySetCanceled<T>(TaskCompletionSource<T> tcs, CancellationToken token)
-        {
-            return tcs.TrySetCanceled();
-        }
-    }
-}
-#endif
-
-#endif

+ 0 - 55
Rx.NET/Source/System.Reactive.Core/Reactive/Internal/TaskServices.cs

@@ -1,55 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the Apache 2.0 License.
-// See the LICENSE file in the project root for more information. 
-
-#if !NO_TPL
-
-using System.ComponentModel;
-using System.Reactive.PlatformServices;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace System.Reactive
-{
-    internal static class TaskHelpers
-    {
-        private static Lazy<ITaskServices> s_services = new Lazy<ITaskServices>(Initialize);
-
-        private static ITaskServices Initialize()
-        {
-#pragma warning disable CS0618 // Type or member is obsolete
-            return PlatformEnlightenmentProvider.Current.GetService<ITaskServices>() ?? new DefaultTaskServices();
-#pragma warning restore CS0618 // Type or member is obsolete
-        }
-
-        public static bool TrySetCanceled<T>(this TaskCompletionSource<T> tcs, CancellationToken token)
-        {
-            return s_services.Value.TrySetCanceled(tcs, token);
-        }
-    }
-}
-
-namespace System.Reactive.PlatformServices
-{
-    /// <summary>
-    /// (Infrastructure) Services to leverage evolving TPL Task APIs.
-    /// </summary>
-    /// <remarks>
-    /// This type is used by the Rx infrastructure and not meant for public consumption or implementation.
-    /// No guarantees are made about forward compatibility of the type's functionality and its usage.
-    /// </remarks>
-    [EditorBrowsable(EditorBrowsableState.Never)]
-    public interface ITaskServices
-    {
-        /// <summary>
-        /// Attempts to transition the underlying Task{T} into the Canceled state.
-        /// </summary>
-        /// <typeparam name="T">Type of the result of the underlying task.</typeparam>
-        /// <param name="tcs">Task completion source whose underlying task to transition into the Canceled state.</param>
-        /// <param name="token">Cancellation token that triggered the cancellation.</param>
-        /// <returns>True if the operation was successful; false if the operation was unsuccessful or the object has already been disposed.</returns>
-        bool TrySetCanceled<T>(TaskCompletionSource<T> tcs, CancellationToken token);
-    }
-}
-
-#endif

+ 6 - 2
Rx.NET/Source/System.Reactive.Linq/Reactive/Linq/QueryLanguage.Imperative.cs

@@ -56,7 +56,11 @@ namespace System.Reactive.Linq
             {
                 ctr = cancellationToken.Register(() =>
                 {
+#if HAS_TPL46
                     tcs.TrySetCanceled(cancellationToken);
+#else
+                    tcs.TrySetCanceled();
+#endif
                     subscription.Dispose();
                 });
             }
@@ -131,9 +135,9 @@ namespace System.Reactive.Linq
         }
 #endif
 
-        #endregion
+#endregion
 
-        #region + Case +
+                #region + Case +
 
         public virtual IObservable<TResult> Case<TValue, TResult>(Func<TValue> selector, IDictionary<TValue, IObservable<TResult>> sources)
         {

+ 4 - 0
Rx.NET/Source/System.Reactive.Linq/Reactive/Threading/Tasks/TaskObservableExtensions.cs

@@ -337,7 +337,11 @@ namespace System.Reactive.Threading.Tasks
             private void Cancel()
             {
                 this._disposable.Dispose();
+#if HAS_TPL46
                 this._tcs.TrySetCanceled(this._ct);
+#else
+                this._tcs.TrySetCanceled();
+#endif
             }
         }
 

+ 0 - 7
Rx.NET/Source/System.Reactive.PlatformServices/Reactive/Internal/PlatformEnlightenmentProvider.cs

@@ -71,13 +71,6 @@ namespace System.Reactive.PlatformServices
             }
 #endif
 
-#if HAS_TPL46
-            if (t == typeof(ITaskServices))
-            {
-                return (T)(object)new TaskServicesImpl();
-            }
-#endif
-
             if (t == typeof(IQueryServices))
             {
                 //

+ 0 - 28
Rx.NET/Source/System.Reactive.PlatformServices/Reactive/Internal/TaskServicesImpl.cs

@@ -1,28 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the Apache 2.0 License.
-// See the LICENSE file in the project root for more information. 
-
-#if !NO_TPL
-
-using System.Threading;
-using System.Threading.Tasks;
-
-#if HAS_TPL46
-namespace System.Reactive.PlatformServices
-{
-    //
-    // WARNING: This code is kept *identically* in two places. One copy is kept in System.Reactive.Core for non-PLIB platforms.
-    //          Another copy is kept in System.Reactive.PlatformServices to enlighten the default lowest common denominator
-    //          behavior of Rx for PLIB when used on a more capable platform.
-    //
-    internal class /*Default*/TaskServicesImpl : ITaskServices
-    {
-        public bool TrySetCanceled<T>(TaskCompletionSource<T> tcs, CancellationToken token)
-        {
-            return tcs.TrySetCanceled(token);
-        }
-    }
-}
-#endif
-
-#endif