Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions src/AsyncEnumerable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public abstract class AsyncEnumerable : IAsyncEnumerable
/// </summary>
public static IAsyncEnumerable<T> Empty<T>() => AsyncEnumerable<T>.Empty;

/// <summary>
///
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken)
{
throw new NotImplementedException();
Expand Down Expand Up @@ -62,17 +67,36 @@ public AsyncEnumerable(Func<AsyncEnumerator<T>.Yield, Task> enumerationFunction)
{
_enumerationFunction = enumerationFunction;
}
/// <summary>
/// Constructor
/// </summary>
/// <remarks>
/// It has been pointed out that overhead costs can be reduced by returning this instead of a new object for the enumerator
/// </remarks>
protected AsyncEnumerable()
{

}

/// <summary>
/// Creates an enumerator that iterates through a collection asynchronously
/// </summary>
/// <param name="cancellationToken">A cancellation token to cancel creation of the enumerator in case if it takes a lot of time</param>
/// <returns>Returns a task with the created enumerator as result on completion</returns>
public IAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToken = default)
=> new AsyncEnumerator<T>(_enumerationFunction) { MasterCancellationToken = cancellationToken };
=> new AsyncEnumerator<T>(_enumerationFunction ?? GetEnumerationFunction()) { MasterCancellationToken = cancellationToken };

IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken)
=> new AsyncEnumerator<T>(_enumerationFunction) { MasterCancellationToken = cancellationToken };
=> new AsyncEnumerator<T>(_enumerationFunction ?? GetEnumerationFunction()) { MasterCancellationToken = cancellationToken };

/// <summary>
/// Gets a EnumerationFunction which allows for a user to inherit from <see cref="AsyncEnumerator{T}"/>
/// </summary>
/// <returns></returns>
public virtual Func<AsyncEnumerator<T>.Yield, Task> GetEnumerationFunction()
{
throw new NotImplementedException();
}
}

/// <summary>
Expand Down