-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Proposal: Add AsyncEnumerable.Empty<T>() #1128
Comments
This is a library feature so should be asked at dotnet/runtime |
By the way, IAsyncEnumerable is just a normal interface. It should be extremely easy to implement AsyncEnumerable.Empty yourself. |
Sorry, I was unsure about where to ask that. Can someone move the issue to the appropriate repo or do I need to close this to submit it to the repo? Yes, I should be able to implement that myself, but something inside the framework would be really helpful. |
It can be moved, but it's probably quicker to just do it yourself :-). The System.Async.Linq nuget package has an Empty method. |
It's available in System.Linq.Async https://github.com/dotnet/reactive/blob/master/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Empty.cs |
OK, so if you think that it doesn't make sense to add it to the runtime, this can be closed. |
This wouldn't be the place to make that call anyway. |
This would be a runtime (previously corefx) issue. |
We don't currently have any plans to add async LINQ equivalents to dotnet/runtime. As called out by previous commenters, the System.Linq.Async nuget package provides an extensive set of such helpers, including Empty. And as was pointed out in the original comments, you can write your own simple version of this: #pragma warning disable CS1998
private static async IAsyncEnumerable<T> Empty<T>()
#pragma warning restore CS1998
{
yield break;
} As such, I'm going to close the issue, but it can always be revisited in the future if it proves to be a significant pain point. |
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
AsyncEnumerable
static class that contains anEmpty<T>()
static method.In that case, I would just write:
Workarounds
I found this which works but is quite weird:
The text was updated successfully, but these errors were encountered: