microsoftgraph / microsoftgraph/msgraph-sdk-dotnet
Support IAsyncEnumerable out of the box
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 789
- Forks
- 264
- Avg merge
- 15h 17m
- Merged PRs (30d)
- 3
Description
Is your feature request related to a problem? Please describe.
This is not so much a problem, but difficult to implement as there is no abstracted concept of page (see https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/511). Every request has its own GetAsync(CancellationToken) and each page has its own NextPageRequest.
Describe the solution you'd like
I'd love to be able to do something like the following:
g.Groups["some id"]
.Members
.Request()
.ToAsyncEnumerable(token);
This allows for processing in memory of what needs to be done, but the paging occurs without any intervention on command if needed.
Describe alternatives you've considered
I've implemented this manually for some of the collections I care about. For example:
public static IAsyncEnumerable<string> GetUserIds(this IGraphServiceClient g, CancellationToken token)
{
return g.Groups["some id"]
.Members
.Request()
.ToAsyncEnumerable(token)
.Select(d => d.Id);
}
private static async IAsyncEnumerable<DirectoryObject> ToAsyncEnumerable(this IGroupMembersCollectionWithReferencesRequest request, [EnumeratorCancellation] CancellationToken token)
{
if (request is null)
{
throw new ArgumentNullException(nameof(request));
}
do
{
var page = await request.GetAsync(token).ConfigureAwait(false);
foreach (var item in page)
{
yield return item;
}
request = page.NextPageRequest;
} while (request != null);
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the collection request types that expose GetAsync(CancellationToken) and page.NextPageRequest, using the Members request in the issue as the entry point. Compare that flow with the provided ToAsyncEnumerable implementation and determine how the abstraction would apply across requests. Done means the shown request chain supports asynchronous iteration, automatic paging, and cancellation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100