diff --git a/src/AsyncEnumerable.cs b/src/AsyncEnumerable.cs index bfcefe2..cb3b893 100644 --- a/src/AsyncEnumerable.cs +++ b/src/AsyncEnumerable.cs @@ -17,6 +17,11 @@ public abstract class AsyncEnumerable : IAsyncEnumerable /// public static IAsyncEnumerable Empty() => AsyncEnumerable.Empty; + /// + /// + /// + /// + /// IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) { throw new NotImplementedException(); @@ -62,6 +67,16 @@ public AsyncEnumerable(Func.Yield, Task> enumerationFunction) { _enumerationFunction = enumerationFunction; } + /// + /// Constructor + /// + /// + /// It has been pointed out that overhead costs can be reduced by returning this instead of a new object for the enumerator + /// + protected AsyncEnumerable() + { + + } /// /// Creates an enumerator that iterates through a collection asynchronously @@ -69,10 +84,19 @@ public AsyncEnumerable(Func.Yield, Task> enumerationFunction) /// A cancellation token to cancel creation of the enumerator in case if it takes a lot of time /// Returns a task with the created enumerator as result on completion public IAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) - => new AsyncEnumerator(_enumerationFunction) { MasterCancellationToken = cancellationToken }; + => new AsyncEnumerator(_enumerationFunction ?? GetEnumerationFunction()) { MasterCancellationToken = cancellationToken }; IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) - => new AsyncEnumerator(_enumerationFunction) { MasterCancellationToken = cancellationToken }; + => new AsyncEnumerator(_enumerationFunction ?? GetEnumerationFunction()) { MasterCancellationToken = cancellationToken }; + + /// + /// Gets a EnumerationFunction which allows for a user to inherit from + /// + /// + public virtual Func.Yield, Task> GetEnumerationFunction() + { + throw new NotImplementedException(); + } } ///