-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
The Pager does not seem to expose the current cursor for the page:
public interface Pager<TItem> : IAsyncEnumerable<TItem>
{
Page<TItem> CurrentPage { get; }
bool HasNextPage { get; }
Task<Page<TItem>> GetNextPageAsync(CancellationToken cancellationToken = default(CancellationToken));
IAsyncEnumerable<Page<TItem>> AsPagesAsync(CancellationToken cancellationToken = default(CancellationToken));
}If this is added, it would make life easier when trying to do iteration in the following pseudo manner:
Job_PageThroughEmployees(cursor? = null)
{
// Get pager for employees:
employeesPager = employeesClient.ListAsync(cursor);
// Get current page from the pager:
employeesPage = employeesPager.CurrentPage
// For each employee in the page, set up a task to deal with employees in an "atomic" manner:
foreach( employee in employeesPage ){
// Queues up another task on a separate thread and function:
Queue(
Job_MigrateSingleEmployee(employee.id)
);
}
// If another page, run this function again but for the next cursor:
if( employeesPager.HasNextPage )
{
Queue(
Job_PageThroughEmployees( employeesPager.next )
);
}
}In the above pseudo example, processing of a page's items can be specific to that cursor. This avoids having to pass the entire serialized Pager to another queued task which can cause problems (For example, when using something like Hangfire for task queues).
I can see that there was thought for this, given that the ListAsync method through EmployeesListRequest has a cursor property.
Metadata
Metadata
Assignees
Labels
No labels