Skip to content

feat: Add IAsyncEnumerable support for auto-pagination#6

Closed
Copilot wants to merge 2 commits intomainfrom
copilot/add-iasyncenumerable-support
Closed

feat: Add IAsyncEnumerable support for auto-pagination#6
Copilot wants to merge 2 commits intomainfrom
copilot/add-iasyncenumerable-support

Conversation

Copy link

Copilot AI commented Dec 29, 2025

Adds C# 8.0 async stream support for paginated endpoints, eliminating manual while (next != null) boilerplate. Network calls trigger lazily as enumeration advances.

Changes

  • New PaginatedStreamExtensions.cs: Extension methods on IUpApi returning IAsyncEnumerable<T> for all paginated endpoints

    • GetTransactionsStreamAsync() - all transactions with filters
    • GetTransactionsStreamAsync(accountId) - account-specific
    • GetAccountsStreamAsync(), GetTagsStreamAsync(), GetAttachmentsStreamAsync(), GetWebhooksStreamAsync(), GetWebhookLogsStreamAsync()
    • All methods accept CancellationToken via [EnumeratorCancellation]
  • Updated README: Streaming examples and API reference

  • Updated Sandbox: Demonstrations including cancellation and short-circuit patterns

Usage

// Automatic pagination
await foreach (var tx in upApi.GetTransactionsStreamAsync(tag: "food")) 
{
    Process(tx); // Fetches next page when buffer exhausted
}

// Short-circuits network calls
await foreach (var tx in upApi.GetTransactionsStreamAsync())
{
    if (tx.Attributes.Amount.Value > 100) break;
}

// LINQ composition (with System.Linq.Async)
var expensive = await upApi.GetTransactionsStreamAsync()
    .Where(t => t.Attributes.Amount.Value < -100)
    .FirstOrDefaultAsync();

Zero breaking changes. Maintains AOT compatibility.

Original prompt

This section details on the original issue you should resolve

<issue_title>feat: Add IAsyncEnumerable support for auto-pagination</issue_title>
<issue_description>Description:

Context
Current manual while (next != null) pagination is imperative boilerplate. Consumers frequently need to stream result sets (ETL, accumulation) without managing page cursors.

Proposal
Expose IAsyncEnumerable<T> wrappers for paginated endpoints to enable C# 8.0 Async Streams.

Spec

  • Behavior: Lazy evaluation. Network calls trigger only as enumeration advances past the current page buffer.
  • Cancellation: Pass CancellationToken through the enumerator.

Usage Definition

// Streaming (Automatic paging behind the scenes)
await foreach (var tx in upApi.GetTransactionsStreamAsync(tag: "food")) 
{
    // Yields items individually; blocks on network only when page buffer is exhausted
    Process(tx);
}

// Composition (System.Linq.Async)
var targetTx = await upApi.GetTransactionsStreamAsync()
    .Where(t => t.Attributes.Amount.Value > 100)
    .FirstOrDefaultAsync(); // Short-circuits network calls on match

Implementation Note
Likely requires an extension method or core refactor to yield items from Data array, then await Next link, rinse/repeat.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Add IAsyncEnumerable support for auto-pagination feat: Add IAsyncEnumerable support for auto-pagination Dec 29, 2025
Copilot AI requested a review from Hona December 29, 2025 23:40
@Hona Hona closed this Feb 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Add IAsyncEnumerable support for auto-pagination

2 participants