Skip to content

CancellationToken support for Paginators #2553

Open
@burck1

Description

@burck1

Describe the feature

Add support for CancellationTokens with Paginators so that paginated requests can be canceled.

Use Case

I'm building a CLI that uses CancellationTokens to cancel requests when the user presses Ctrl-C (SIGINT). I'd like to be able to use the AWS SDK's Paginators feature in my CLI and still allow users to cancel requests, but it doesn't look like there is an easy way to provide a CancellationToken for a request with Paginators.

Proposed Solution

In the Paginators example, you can find the following example code:

var paginatorForLogGroups = cwClient.Paginators.DescribeLogGroups(new DescribeLogGroupsRequest());
await foreach(var logGroup in paginatorForLogGroups.LogGroups)
{
    Console.WriteLine(logGroup.LogGroupName);
}

Ideally we would simply be able to pass in a cancellation token to the request like the existing DescribeLogGroupsAsync(CancellationToken) and DescribeLogGroupsAsync(DescribeLogGroupsRequest, CancellationToken) functions. Something like:

var paginatorForLogGroups = cwClient.Paginators.DescribeLogGroups(new DescribeLogGroupsRequest(), cancellationToken);
await foreach(var logGroup in paginatorForLogGroups.LogGroups)
{
    Console.WriteLine(logGroup.LogGroupName);
}

Other Information

I'm certainly no C# expert, but I thing the cancellation token would need to both be passed through to the http request being made by the AWS SDK and it would need need to be configured on the IAsyncEnumerable Interface, perhaps using the WithCancellation extension method.

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

AWS .NET SDK and/or Package version used

Any of the latest AWS SDK for .NET Version 3 clients that support Paginators

Targeted .NET Platform

.NET Core 3.1, .NET 6, .NET 7

Operating System and version

Any

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions