Class PagedAsyncEnumerable<TResponse, TResource>
An asynchronous sequence of resources obtained via API responses. Application code can treat this as a simple sequence (with API calls automatically being made lazily as more results are required), or call AsRawResponses() to retrieve one API response at a time, potentially with additional information.
Inheritance
Implements
Inherited Members
Namespace: Google.Api.Gax
Assembly: Google.Api.Gax.dll
Syntax
public abstract class PagedAsyncEnumerable<TResponse, TResource> : IAsyncEnumerable<TResource>
Type Parameters
Name | Description |
---|---|
TResponse | The API response type. Each response contains a page of resources. |
TResource | The resource type contained within the response. |
Methods
AsRawResponses()
Returns the sequence of raw API responses, each of which contributes a page of resources to this sequence.
Declaration
public virtual IAsyncEnumerable<TResponse> AsRawResponses()
Returns
Type | Description |
---|---|
System.Collections.Generic.IAsyncEnumerable<TResponse> | An asynchronous sequence of raw API responses, each containing a page of resources. |
GetAsyncEnumerator(CancellationToken)
Declaration
public virtual IAsyncEnumerator<TResource> GetAsyncEnumerator(CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
System.Threading.CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
System.Collections.Generic.IAsyncEnumerator<TResource> |
Implements
ReadPageAsync(Int32, CancellationToken)
Eagerly (but asynchronously) reads a single page of results with a fixed maximum size. The returned page is guaranteed to have that many results, unless there is no more data available.
Declaration
public virtual Task<Page<TResource>> ReadPageAsync(int pageSize, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | pageSize | The page size. Must be greater than 0. |
System.Threading.CancellationToken | cancellationToken | A token to cancel the operation. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<Page<TResource>> | An asynchronous operation, the result of which is a page of resources. |
Remarks
"Natural" pages returned by the API may contain a smaller number of resources than requested. For example, a request for a page with 100 resources may return a page with 80 resources but a next page token for more to be retrieved. This is suitable for batch-processing, but not for user-visible paging such as in a web application, where fixed-size pages are expected. This method may make more than one API call in order to fill the page, but after the page has been returned, all the data will have been loaded. (In particular, iterating over the items in the page multiple times will not make any further requests.)