-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[MetricsAdvisor] Make collections returned by service methods pageables #16049
Conversation
sdk/metricsadvisor/Azure.AI.MetricsAdvisor/src/MetricsAdvisorAdministrationClient.cs
Show resolved
Hide resolved
|
||
List<AnomalyAlertConfiguration> getAlertConfigs = new List<AnomalyAlertConfiguration>(); | ||
|
||
await foreach (var config in adminClient.GetAnomalyAlertConfigurationsAsync(createdAnomalyDetectionConfiguration.Id)) |
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.
Me learning, is this the only way to get the list of items after they are in the AsyncPageable
type?
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.
It's the only "natural" approach, as far as I know. AsyncPageable implements the IAsyncEnumerable interface, and that's why it's accessed like this (more info about them here).
I think you could do something like this as well:
var enumerator = adminClient.GetSomethingAsync(...).GetAsyncEnumerator();
while (await enumerator.MoveNextAsync())
{
var element = enumerator.Current;
// Do something with <element>
}
That's probably what happens under the hood. I don't see a good reason for preferring this approach, though (maybe if you're using an older version of C# and can't use await foreach
).
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 remembered I saw this somewhere once in appconfig. You could use ToEnumerableAsync.
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.
This is only a convenience method in our test framework, though. Good to know.
I thought you were asking from a user's point of view.
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.
Sorry, I forgot about this one!
Updated methods that return IReadOnlyList to return pageables. Getting this PR out first so the samples PR doesn't get too big.
Fixes #15927.