Skip to content

Add ability to retrieve cursor for current page #60

@jamestrusler

Description

@jamestrusler

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions