Add IAsyncEnumerable and IAsyncEnumerator
authorStephen Toub <stoub@microsoft.com>
Tue, 16 Oct 2018 01:21:08 +0000 (21:21 -0400)
committerStephen Toub <stoub@microsoft.com>
Fri, 26 Oct 2018 04:02:40 +0000 (21:02 -0700)
Commit migrated from https://github.com/dotnet/coreclr/commit/9d811158195826ca1a2211c996b56c3314325a44

src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IAsyncEnumerable.cs [new file with mode: 0644]
src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IAsyncEnumerator.cs [new file with mode: 0644]

index 25b0dbb..5530742 100644 (file)
@@ -72,6 +72,8 @@
     <Compile Include="$(MSBuildThisFileDirectory)System\Collections\DictionaryEntry.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\ArraySortHelper.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\Dictionary.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\IAsyncEnumerable.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\IAsyncEnumerator.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\ICollection.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\ICollectionDebugView.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Collections\Generic\IComparer.cs" />
diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IAsyncEnumerable.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IAsyncEnumerable.cs
new file mode 100644 (file)
index 0000000..ef02070
--- /dev/null
@@ -0,0 +1,15 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace System.Collections.Generic
+{
+    /// <summary>Exposes an enumerator that provides asynchronous iteration over values of a specified type.</summary>
+    /// <typeparam name="T">The type of values to enumerate.</typeparam>
+    public interface IAsyncEnumerable<out T>
+    {
+        /// <summary>Returns an enumerator that iterates asynchronously through the collection.</summary>
+        /// <returns>An enumerator that can be used to iterate asynchronously through the collection.</returns>
+        IAsyncEnumerator<T> GetAsyncEnumerator();
+    }
+}
diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IAsyncEnumerator.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IAsyncEnumerator.cs
new file mode 100644 (file)
index 0000000..0d9afc1
--- /dev/null
@@ -0,0 +1,24 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Threading.Tasks;
+
+namespace System.Collections.Generic
+{
+    /// <summary>Supports a simple asynchronous iteration over a generic collection.</summary>
+    /// <typeparam name="T">The type of objects to enumerate.</typeparam>
+    public interface IAsyncEnumerator<out T> : IAsyncDisposable
+    {
+        /// <summary>Advances the enumerator asynchronously to the next element of the collection.</summary>
+        /// <returns>
+        /// A <see cref="ValueTask{Boolean}"/> that will complete with a result of <c>true</c> if the enumerator
+        /// was successfully advanced to the next element, or <c>false</c> if the enumerator has passed the end
+        /// of the collection.
+        /// </returns>
+        ValueTask<bool> MoveNextAsync();
+
+        /// <summary>Gets the element in the collection at the current position of the enumerator.</summary>
+        T Current { get; }
+    }
+}