Skip to content
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

Add support for IAsyncEnumerable<T> #903

Closed
thomaslevesque opened this issue Oct 12, 2019 · 12 comments · May be fixed by #4855
Closed

Add support for IAsyncEnumerable<T> #903

thomaslevesque opened this issue Oct 12, 2019 · 12 comments · May be fixed by #4855
Labels
VNext Next Major version of SDK

Comments

@thomaslevesque
Copy link
Contributor

thomaslevesque commented Oct 12, 2019

Is your feature request related to a problem? Please describe.

The API for enumerating query results isn't great, because it forces the user to be aware of the fact that the results are fetched page by page:

var iterator = ...
while (iterator.HasMoreResults)
{
    var page = await iterator.ReadNextAsync();
    foreach (var item in page)
    {
        ...
    }
}

Describe the solution you'd like

The FeedIterator<T> API is useful, because it gives you more information (e.g. request charge), but in most cases the user just wants the results, so it would be nice to have a higher level abstraction. The IAsyncEnumerable<T> interface seems perfect for this.

There could be an AsAsyncEnumerable extension method like this:

public static async IAsyncEnumerable<T> AsAsyncEnumerable<T>(
    this FeedIterator<T> iterator,
    [EnumeratorCancellation] CancellationToken cancellationToken = default)
{
    while (iterator.HasMoreResults)
    {
        var page = await iterator.ReadNextAsync(cancellationToken);
        foreach (var item in page)
        {
            cancellationToken.ThrowIfCancellationRequested();
            yield return item;
        }
    }
}

The consuming code would be simplified to this:

var iterator = ...
await foreach (var item in iterator.AsAsyncEnumerable())
{
    ...
}

Describe alternatives you've considered
N/A

Additional context

The await foreach feature was introduced in C# 8, so this would only be useful to people already using C# 8.
However, the Microsoft.Bcl.AsyncInterfaces package is compatible with netstandard2.0 and net461, so it wouldn't require running .NET Core 3.

@ealsur ealsur added the VNext Next Major version of SDK label Oct 14, 2019
@ealsur
Copy link
Member

ealsur commented Oct 14, 2019

We are working on this at the moment 😄

@thomaslevesque
Copy link
Contributor Author

Awesome!

@ealsur
Copy link
Member

ealsur commented Nov 7, 2019

@ealsur ealsur closed this as completed Nov 7, 2019
@thomaslevesque
Copy link
Contributor Author

Cool, thanks!

@cfindlayvcs
Copy link

cfindlayvcs commented Dec 2, 2020

@ealsur , I just tried this with the latest version of the Cosmos DB API (3.15.2) on .NET Core 3.1 and GetItemQueryIterator<> does not return IAsyncEnumerable. I get this:

There is no 4.0 preview package.

image

@lorenpaulsen
Copy link

@ealsur , I just tried this with the latest version of the Cosmos DB API (3.15.2) on .NET Core 3.1 and GetItemQueryIterator<> does not return IAsyncEnumerable. I get this:

There is no 4.0 preview package.

image

The 4.0 preview package can be found here: https://www.nuget.org/packages/Azure.Cosmos

@thomaslevesque
Copy link
Contributor Author

The 4.0 preview package can be found here: https://www.nuget.org/packages/Azure.Cosmos

Indeed. Honestly, I'm not sure how we're supposed to guess that.

  • The README says it's the repo for "Version 3", with no mention of a version 4
  • The README still points to the old package and doesn't mention the new one
  • The old package doesn't mention that it's been superseded by a new one
  • The new package points to this repo, which doesn't seem to know anything about the new package

I think I discovered the new package by accident in an article. There's almost no chance a new user will find it if they end up on this repo.

@paulirwin
Copy link

Is there an anticipated release date for the v4 SDK? It looks like the last preview came out almost a year and a half ago. Thanks for any updates!

@Socolin
Copy link

Socolin commented Jan 25, 2022

Hello, is there any ETA for this ? It look like the v4 is abandon since 2 year, is there any reason for this ?

@bartelink
Copy link
Contributor

See #2976

@dersia
Copy link

dersia commented Jun 13, 2023

as of the comment #2976 (comment) I'd like to ask to reopen this issue. a feature like this needs to in the sdk, if it's not v4, then in v3, but this is very much needed.

Maybe @jcocchi can help with this?

@onionhammer
Copy link
Contributor

Any movement on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
VNext Next Major version of SDK
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants