Browse Source

Remove two more uses of AsyncEnumerable.Create.

Bart De Smet 5 years ago
parent
commit
3fc89745e1

+ 2 - 2
Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Amb.cs

@@ -160,9 +160,9 @@ namespace System.Linq
             if (sources == null)
                 throw Error.ArgumentNull(nameof(sources));
 
-            return AsyncEnumerable.Create(Core);
+            return Core(sources);
 
-            async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
+            static async IAsyncEnumerable<TSource> Core(IAsyncEnumerable<TSource>[] sources, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken = default)
             {
                 //
                 // REVIEW: See remarks on binary overload for changes compared to the original.

+ 21 - 26
Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Catch.cs

@@ -255,46 +255,41 @@ namespace System.Linq
             return CatchCore(new[] { first, second });
         }
 
-        private static IAsyncEnumerable<TSource> CatchCore<TSource>(IEnumerable<IAsyncEnumerable<TSource>> sources)
+        private static async IAsyncEnumerable<TSource> CatchCore<TSource>(IEnumerable<IAsyncEnumerable<TSource>> sources, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken = default)
         {
-            return AsyncEnumerable.Create(Core);
+            var error = default(ExceptionDispatchInfo);
 
-            async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
+            foreach (var source in sources)
             {
-                var error = default(ExceptionDispatchInfo);
+                await using var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false);
 
-                foreach (var source in sources)
-                {
-                    await using var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false);
+                error = null;
 
-                    error = null;
+                while (true)
+                {
+                    TSource c;
 
-                    while (true)
+                    try
                     {
-                        TSource c;
-
-                        try
-                        {
-                            if (!await e.MoveNextAsync())
-                                break;
-
-                            c = e.Current;
-                        }
-                        catch (Exception ex)
-                        {
-                            error = ExceptionDispatchInfo.Capture(ex);
+                        if (!await e.MoveNextAsync())
                             break;
-                        }
 
-                        yield return c;
+                        c = e.Current;
                     }
-
-                    if (error == null)
+                    catch (Exception ex)
+                    {
+                        error = ExceptionDispatchInfo.Capture(ex);
                         break;
+                    }
+
+                    yield return c;
                 }
 
-                error?.Throw();
+                if (error == null)
+                    break;
             }
+
+            error?.Throw();
         }
     }
 }