using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace Amazon.Runtime
{
///
/// An enumerable containing all of the responses for a paginated
/// operation
///
///
public class PaginatedResponse : IPaginatedEnumerable
{
private readonly IPaginator _paginator;
///
/// Create a PaginatedResponse object by providing
/// any operation paginator
///
///
public PaginatedResponse(IPaginator paginator)
{
this._paginator = paginator;
}
#if AWS_ASYNC_ENUMERABLES_API
///
/// Get responses asynchronously
///
///
///
public async IAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = default)
{
await foreach (var response in _paginator.PaginateAsync().WithCancellation(cancellationToken).ConfigureAwait(false))
{
cancellationToken.ThrowIfCancellationRequested();
yield return response;
}
}
#endif
#if BCL
///
/// Get responses synchronously
///
///
public IEnumerator GetEnumerator()
{
return _paginator.Paginate().GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
#endif
}
}