microsoftgraph / microsoftgraph/msgraph-sdk-dotnet

Support IAsyncEnumerable out of the box

Open
#733 11 comments 11 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Request: feature
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);
}

AB#7248

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.