Skip to content

ClientModel: Pageable abstractions for third-party clients#44026

Merged
annelo-msft merged 70 commits intoAzure:mainfrom
annelo-msft:clientmodel-3p-pageable
May 16, 2024
Merged

ClientModel: Pageable abstractions for third-party clients#44026
annelo-msft merged 70 commits intoAzure:mainfrom
annelo-msft:clientmodel-3p-pageable

Conversation

@annelo-msft
Copy link
Copy Markdown
Contributor

@annelo-msft annelo-msft commented May 14, 2024

Overview

System.ClientModel-based client's service methods need to be able to return collections of values from a paged collection, i.e. where subsets of collection elements are returned iteratively over one more calls to the service. TypeSpec is adding pagination support (see overview and microsoft/typespec#705) and in time our generators will generate third-party clients with such service methods from the TypeSpec.

What's in this PR

This PR adds sync and async abstractions for pageable result collections, PageableCollection<T> and AsyncPageableCollection<T>, as well as a ResultPage<T> type that exposes a continuation token and enables enumeration over the results in the page. It also adds a mock client that illustrates standard patterns for implementing these abstractions, as well as tests that illustrate standard usage patterns of the abstractions, e.g. for changing the size of the page requested from the service, and enumerating results using a page's continuation token.

…convenience implementation in a way that postpones sending the request
@annelo-msft annelo-msft changed the title ClientModel: third-party pageable types ClientModel: Pageable abstractions for third-party clients May 15, 2024
@annelo-msft annelo-msft marked this pull request as ready for review May 15, 2024 22:16
@annelo-msft annelo-msft requested review from a team, KrzysztofCwalina and tg-msft as code owners May 15, 2024 22:16
Comment thread sdk/core/System.ClientModel/src/Convenience/AsyncPageableCollectionOfT.cs Outdated
Comment thread sdk/core/System.ClientModel/src/Convenience/AsyncPageableCollectionOfT.cs Outdated
Comment thread sdk/core/System.ClientModel/src/Convenience/ResultPageOfT.cs Outdated
Copy link
Copy Markdown
Member

@jsquire jsquire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The approach looks reasonable to me.

It's a shame that the sync/async types are different, but it makes sense if we're trying to align how you enumerate to the sync/async version of the operation that was called.

Copy link
Copy Markdown
Member

@jsquire jsquire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing review; request for changes was unintentional and due to a mis-click.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants