-
Notifications
You must be signed in to change notification settings - Fork 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
Champion "Async Streams" (including async disposable) (16.3, Core 3) #43
Comments
This would be something like interface IAsyncEnumerable<T>
{
IAsyncEnumerator<T> GetEnumerator();
}
interface IAsyncEnumerator<T>: IAsyncDisposable
{
Task<bool> MoveNextAsync();
T Current { get; }
} With the following elements yet to be designed
|
@gafter I thought we settled on interface IAsyncEnumerable<T>
{
IAsyncEnumerator<T> GetEnumerator(CancellationToken cancellation);
} And potentially static class AsyncEnumerableExtensions
{
static IAsyncEnumerator<T> GetEnumerator(this IAsyncEnumerable<T> source) => source.GetEnumerator(CancellationToken.None);
} |
After the appearance of "IAsyncEnumerable" in Azure Service Fabric, we want more......... As ecmascript is proposing with generator async, there is to be the fulfilment in .net! wish these come true earlier!!!! |
Any news on this? Seems this interface has been defined in several places already (IX, EF7) |
As brought up in roslyn thread interface IAsyncEnumerator<T>: IAsyncDisposable
{
Task<bool> MoveNextAsync();
T Current { get; }
} Has issues with parallelazation/concurrency/atomicity which is a desirable property of an async system (e.g. double gets on Current or missed items on Current) |
Maybe then:
|
An async method can't have |
Another version:
|
How about just adding |
@IvanKonov This definition would make |
but Task<bool> GetNextAsync(out T next); isn't async Task DoThing()
{
var enumerator = new Enumerator<int>();
while(await enumerator.GetNextAsync(out var next))
{
// Do thing with next
}
}
struct Enumerator<T>
{
public Task<bool> GetNextAsync(out T next)
{
next = default(T);
return Task.FromResult(false);
}
} |
Doesn't the out param have to be set before the task is returned? At that point, the task will most likely not be completed, so you won't have a "next" to pass as the out param. Then, by the time you have your next, it's too late to fill the out param. |
😢 I'll go with @onovotny's suggestion instead then #43 (comment) |
While true, if you have a source that supports multiple readers, you can also simply change the model to one where each reader is given its own enumerator. Then the concurrency issues evaporate / are left up to the coordinator that's giving the items out to the individual enumerators.
I don't understand the suggestion. When I do: Task<bool> t = enumerator.GetMoveNext(out T result);
Use(result);
await t; how is that intended to work?
Note that most of this was already discussed in dotnet/roslyn#261. |
I was trolling, but what if using out parameters with Task required use of await? Then the assignment order is guaranteed. |
a) that would be a breaking change, b) there are actually scenarios where you want to access the |
@stephentoub is there a Cliffs Notes version of that thread? |
In the near future I'm planning to take some time to write down where we are, which would include summarizing salient points from that thread. |
Have you flushed out how CancellationTokens would work here? Is the intent to explicitly call
Would it be possible to get the IEnumerable/LINQ and IObservable/Rx extension methods wired up to IAsyncEnumerable? Do IAsyncQueryable/IAsyncQbservable factor in to the plans at all? |
discriminated unions would be useful here. |
@alrz I guess that would be very tricky. Who will dispose the reader? I think that will only work with buffering of the complete list or with |
RE "Who will dispose the reader" The iterator. async Task<IEnumerable<T>> IteratorAsync() {
var reader = await ExecuteReader();
IEnumerable<T> Iterator() {
using (reader)
while (reader.Read())
yield return RowParser(reader);
}
return Iterator();
} It's not always easy to workaround this, would be nice if the compiler can see if the iterator is not awaiting and permit |
@alrz I see. But it's rather unnoticeable, that you will leak resources if you do not use the |
If the alternative interfaces are used, I don't think there is any benefit to permitting |
I was watching the Build demo of this feature and was wondering how we can specify |
Nevermind, it appears this is being considered in the proposal. |
From May 21 2018 LDM notes:
Since the |
How will async disposables interact with #1174? Will there be an async form of that? |
This link at the top of the document returns a 404 |
Fixed. It moved into the C# 8 folder. |
Should this be closed now? I was under the impression it's completed. |
feature itself is done but they close such issues only when "paperwork" is also done (spec must be written if memory serves right) |
Correct. We'll close this when a spec is merged. |
See dev spec: https://github.com/dotnet/roslyn/blob/main/docs/features/async-streams.md
See also dotnet/roslyn#261
LDM notes:
The text was updated successfully, but these errors were encountered: