-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Feature request: Async stream generators #8
Comments
Only BCL(without Rx) can't handle IObservable[T] easily. async Task RunAsync()
{
// GetData() == IObservable<T>
// syntax proposal(await foreach)
await foreach(var item in GetData())
{
Console.WriteLine(item);
}
} It is equal to following code in Rx. async Task RunAsync()
{
// GetData() == IObservable<T>
await GetData().ForEachAsync(x =>
{
Console.WriteLine(x);
});
} matrix
|
Thanks @neuecc. Completely agree with you. |
I would really like to address the lack of asynchronous sequences in C#. We've discussed this at length since back when we were still adding async/await to the language. There are a couple of issues. First off I am not sure if Another concern is how to best deal with batching/chunking. Oftentimes a data stream would arrive in big chunks. If you access every element of each chunk asynchronously (with await) you are incurring a lot of overhead, and essentially blurring the "degree of asynchrony" of the source. A third issue is query operators. You could certainly imagine implementing the Linq pattern over an asynchronous stream type, but the way query expressions work today, they generate synchronous lambdas, so logic applied in the query clauses themselves couldn't use await. This would be severely limiting. Maybe we can find a way to extend query expressions to deal with this. Language support for asynchronous sequences would at least support iterators, and possibly also foreach loops and asynchronous query expressions. So: this is something I'd love for us to look at for the next version of C#. We would have to land with a design that we are very comfortable with in order to include it. |
The one issue that I agree with being how you'd use I disagree that we'd need yet another interface to represent asynchronous streams. As for query operators, Microsoft already has this project and it works fantastically well. I don't know what kind of conversation needs to happen to get Rx to be shipped as a part of the runtime but just by sticking with |
I don't see much value in reactive stream generators. I do think Ix's |
@MadsTorgersen, I agree that IObservable is not a good candidate for async sequences. And given that Rx.NET provides good enough means to asynchronously produce and consume IObservables I am closing this request with the hope async generator/foreach will find their way to C# 7 ✨ |
I'd like to at least see the consumption of "async streams" use an intermediary, like how I still think that it's a travesty that Rx doesn't get the love from the BCL or language teams. |
Currenty C# supports pull based sequence generators.
As IObservable<T> and IObserver<T> are now in mscorlib and Rx is such a success not only in .NET but in other languages and runtimes why not to add to C# ability to easily create async push based stream generators.
It could look like this:
It would complete language support in the matrix of generators:
The text was updated successfully, but these errors were encountered: