Browse Source

Conditional compilation of ForEachAsync support.

Bart De Smet 7 years ago
parent
commit
a7c9d8cb80

+ 2 - 1
Ix.NET/Source/System.Linq.Async.Tests/System/Linq/Operators/ForEachAsync.cs

@@ -2,8 +2,8 @@
 // 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 !HAS_AWAIT_FOREACH
 using System;
-using System.Collections.Generic;
 using System.Linq;
 using System.Threading;
 using System.Threading.Tasks;
@@ -84,3 +84,4 @@ namespace Tests
         }
     }
 }
+#endif

+ 0 - 8
Ix.NET/Source/System.Linq.Async.Tests/System/Linq/Operators/TakeLast.cs

@@ -62,14 +62,6 @@ namespace Tests
         [Fact]
         public void TakeLast_BugFix_TakeLast_Zero_TakesForever()
         {
-            var isSet = false;
-            new int[] { 1, 2, 3, 4 }.ToAsyncEnumerable()
-                .TakeLast(0)
-                .ForEachAsync(_ => { isSet = true; })
-                .Wait(WaitTimeoutMs);
-
-            Assert.False(isSet);
-
             var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable().TakeLast(0);
 
             var e = xs.GetAsyncEnumerator();

+ 7 - 0
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ForEach.cs

@@ -2,6 +2,7 @@
 // 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 !HAS_AWAIT_FOREACH
 using System.Collections.Generic;
 using System.Threading;
 using System.Threading.Tasks;
@@ -10,6 +11,11 @@ namespace System.Linq
 {
     public static partial class AsyncEnumerable
     {
+        // REVIEW: Once we have C# 8.0 language support, we may want to do away with these methods. An open question is how to
+        //         provide support for cancellation, which could be offered through WithCancellation on the source. If we still
+        //         want to keep these methods, they may be a candidate for System.Interactive.Async if we consider them to be
+        //         non-standard (i.e. IEnumerable<T> doesn't have a ForEach extension method either).
+
         public static Task ForEachAsync<TSource>(this IAsyncEnumerable<TSource> source, Action<TSource> action)
         {
             if (source == null)
@@ -183,3 +189,4 @@ namespace System.Linq
         }
     }
 }
+#endif