Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AsyncEnumerable can be inherited from #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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