Explorar o código

Improve ToEnumerable exception behavior.

Bart De Smet %!s(int64=7) %!d(string=hai) anos
pai
achega
f42f8a6ccd

+ 16 - 18
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ToEnumerable.cs

@@ -13,29 +13,27 @@ namespace System.Linq
             if (source == null)
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
                 throw Error.ArgumentNull(nameof(source));
 
 
-            return ToEnumerableCore(source);
-        }
-
-        private static IEnumerable<TSource> ToEnumerableCore<TSource>(IAsyncEnumerable<TSource> source)
-        {
-            var e = source.GetAsyncEnumerator(default);
+            return Core();
 
 
-            try
+            IEnumerable<TSource> Core()
             {
             {
-                while (true)
-                {
-                    if (!e.MoveNextAsync().Result)
-                        break;
+                var e = source.GetAsyncEnumerator(default);
 
 
-                    var c = e.Current;
+                try
+                {
+                    while (true)
+                    {
+                        if (!e.MoveNextAsync().GetAwaiter().GetResult())
+                            break;
 
 
-                    yield return c;
+                        yield return e.Current;
+                    }
+                }
+                finally
+                {
+                    // Wait
+                    e.DisposeAsync().GetAwaiter().GetResult();
                 }
                 }
-            }
-            finally
-            {
-                // Wait
-                e.DisposeAsync().GetAwaiter().GetResult();
             }
             }
         }
         }
     }
     }