-
Notifications
You must be signed in to change notification settings - Fork 496
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
Implement IAsyncEnumerable on CosmosLinqQuery #4355
Implement IAsyncEnumerable on CosmosLinqQuery #4355
Conversation
Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemLinqTests.cs
Outdated
Show resolved
Hide resolved
…ts. Dispose feed iterator in GetEnumerator
How about if it yielded an For instance, I'd be able to use such a slightly lower level mechanism as a building block in wrappers that I find critical in successful usage:
Same for |
You're not forced to use it? And this opens up capabilities for improved integration with other libraries, such as HotChocolate. Enumerating a "FeedResponse" would make observers have to know about the Cosmos SDK in a way that the proposed implementation does not. You can already do foreach() on a query (it implements IEnumerable) - but it will almost certainly error because of requiring the "allow synchronous" flag, this just adds the IAsyncEnumerable counterpart. |
I am not saying this isnt useful. But exposing Not sure if implementing two IAsyncEnumerable interfaces will make a mess; if it did, maybe that could be My point is simply to consider what happens the minute you need to add instrumentation - it's not disssimilar to #692 (comment) - thinking about what happens after someone hits the limits of what is exposed - do they fall off a cliff and have to work out lots of things that are a big jump. None of this is to invalidate the usefulness of what you're adding; having this in the box is absolutely transformative and a no brainer to add. |
I think this would be useful as an additional extension method to elide some of the iterator ugliness |
thanks for this! And I appreciate your work here, but this PR would not Close #903 because it is adding Also I would like to point out that I would love for having said that, I don't know if the server supports http-streaming yet. |
Is this being addressed? In reply to: 2012904380 Refers to: Microsoft.Azure.Cosmos/src/Linq/CosmosLinqQuery.cs:104 in 9b513c7. [](commit_id = 9b513c7, deletion_comment = False) |
Hi @adityasa I must have missed that one - apologies. I'm not sure if I agree that this is necessary/good; I assume to be DRY? The code is different enough where it would be annoying to call synchronously, unless you have a better way IAsyncEnumerator<T> asyncEnumerator = this.GetAsyncEnumerator();
while (true)
{
ValueTask<bool> moveNextTask = asyncEnumerator.MoveNextAsync();
if (!moveNextTask.IsCompletedSuccessfully)
{
#pragma warning disable VSTHRD002 // Avoid problematic synchronous waits
if (!TaskHelper.InlineIfPossible(() => moveNextTask.AsTask(), null).GetAwaiter().GetResult())
{
break;
}
#pragma warning disable VSTHRD002 // Avoid problematic synchronous waits
}
else if (!moveNextTask.Result)
{
break;
}
yield return asyncEnumerator.Current;
}
ValueTask disposeTask = asyncEnumerator.DisposeAsync();
if (!disposeTask.IsCompletedSuccessfully)
{
#pragma warning disable VSTHRD002 // Avoid problematic synchronous waits
TaskHelper.InlineIfPossible(() => asyncEnumerator.DisposeAsync().AsTask().ContinueWith(t => true), null).GetAwaiter().GetResult();
#pragma warning disable VSTHRD002 // Avoid problematic synchronous waits
} |
…se `CosmosLinqQuery<T>` instead of `IAsyncEnumerable<T>`
No worries. I have a simple sample below. Is something like this possible? public IEnumerator GetEnumerator() In reply to: 2066546588 |
This code does not dispose the enumerator (which is IAsyncDisposable) |
The example above does not achieve disposal, so it may not be sufficient. In reply to: 2077739958 |
@adityasa are you just trying to make it DRY? I think the current implementation (keeping GetEnumerator as it is today) is much simpler |
Yes. In general, I would like to avoid inheritance (and favor composition) and for cases like this where there isn't a suitable option (since we already implemented IEnumerable and IAsyncEnumerable is more general), at least avoid code duplication. In reply to: 2077756442 |
Okay; if you still want me to move ahead with that change, let me know - I think it increases the code-size and complexity to be "DRY" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that the full implementation increases the complexity and compared to that current implementation is sufficient. In reply to: 2108024057 |
@adityasa any status update on this? |
@adityasa any update? |
Closing due to in-activity, feel free to re-open as needed |
Pull Request Template
Description
This updates CosmosLinqQuery to support IAsyncEnumerable, a new 'AsAsyncEnumerable' extension method, and a test method to utilize the new extension method
Type of change
Please delete options that are not relevant.