Rationale
I have an interface which is written like this:
public interface IItemRetriever
{
public IAsyncEnumerable<string> GetItemsAsync();
}
I want to write an empty implementation that returns no item, like so:
public class EmptyItemRetriever : IItemRetriever
{
public IAsyncEnumerable<string> GetItemsAsync()
{
// What do I put here if nothing is to be done?
}
}
If it was a plain IEnumerable, I would return Enumerable.Empty<string>();, but I didn't find any AsyncEnumerable.Empty<string>().
Proposal
Create an AsyncEnumerable static class that contains an Empty<T>() static method.
In that case, I would just write:
return AsyncEnumerable.Empty<string>();
Workarounds
I found this which works but is quite weird:
public async IAsyncEnumerable<string> GetItemsAsync()
{
await Task.CompletedTask;
yield break;
}
Rationale
I have an interface which is written like this:
I want to write an empty implementation that returns no item, like so:
If it was a plain IEnumerable, I would
return Enumerable.Empty<string>();, but I didn't find anyAsyncEnumerable.Empty<string>().Proposal
Create an
AsyncEnumerablestatic class that contains anEmpty<T>()static method.In that case, I would just write:
Workarounds
I found this which works but is quite weird: