Browse Source

Hand-rolling Empty iterator.

Bart De Smet 8 years ago
parent
commit
e47142a5a7
1 changed files with 8 additions and 1 deletions
  1. 8 1
      Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Empty.cs

+ 8 - 1
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Empty.cs

@@ -11,7 +11,14 @@ namespace System.Linq
     {
         public static IAsyncEnumerable<TValue> Empty<TValue>()
         {
-            return CreateEnumerable(() => CreateEnumerator<TValue>(ct => TaskExt.False, current: null, dispose: null));
+            return new EmptyAsyncIterator<TValue>();
+        }
+
+        private sealed class EmptyAsyncIterator<TValue> : AsyncIterator<TValue>
+        {
+            public override AsyncIterator<TValue> Clone() => new EmptyAsyncIterator<TValue>();
+
+            protected override Task<bool> MoveNextCore() => TaskExt.False;
         }
     }
 }