paging

package
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: AGPL-3.0 Imports: 3 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pager

type Pager[T any] struct {
	// contains filtered or unexported fields
}

Pager keeps a long list sparse and loads the requested page plus a small read-ahead window. fetch receives one-based page numbers; all other methods use zero-based item/page indexes.

func New

func New[T any](size, ahead int, post func(func()), fetch func(page int) ([]T, int, error)) *Pager[T]

New constructs a pager. post is called by worker completions on the owner goroutine; tests may pass a synchronous function.

func NewScoped

func NewScoped[T any](ctx context.Context, size, ahead int, post func(func()), fetch func(context.Context, int) ([]T, int, error)) *Pager[T]

NewScoped binds page requests to the plugin activation that starts them.

func (*Pager[T]) Around

func (p *Pager[T]) Around(i int) (items []T, at, end int)

Around returns the contiguous loaded run containing i, the item's offset, and the end index of the run.

func (*Pager[T]) At

func (p *Pager[T]) At(i int) *T

At returns item i when its page is loaded, otherwise nil and starts loading.

func (*Pager[T]) Error

func (p *Pager[T]) Error() error

Error returns the most recent page error, if one is available.

func (*Pager[T]) FailedAt

func (p *Pager[T]) FailedAt(i int) bool

FailedAt reports whether the page containing item i failed.

func (*Pager[T]) IndexOf

func (p *Pager[T]) IndexOf(fn func(*T) bool) int

IndexOf finds the first loaded item matching fn without starting requests.

func (*Pager[T]) Land

func (p *Pager[T]) Land(pg int, items []T, total int)

Land applies a page result. It is exported for deterministic adapters and tests that already have a response.

func (*Pager[T]) Len

func (p *Pager[T]) Len() int

Len returns the known list length, or zero while it is unknown.

func (*Pager[T]) PageCount

func (p *Pager[T]) PageCount() int

PageCount returns the number of physical pages once the total is known.

func (*Pager[T]) PageSize

func (p *Pager[T]) PageSize() int

PageSize returns the number of items requested per physical page.

func (*Pager[T]) Peek

func (p *Pager[T]) Peek(i int) *T

Peek returns a loaded item without starting a network request.

func (*Pager[T]) Reload

func (p *Pager[T]) Reload()

Reload invalidates every page while keeping the known total and list geometry. This lets a sort or filter change show stable rows and skeletons instead of collapsing the whole page back to an unknown loading state.

func (*Pager[T]) RemoveAt

func (p *Pager[T]) RemoveAt(i int)

RemoveAt removes item i and invalidates pages that shifted after it.

func (*Pager[T]) Retry

func (p *Pager[T]) Retry()

Retry makes failed pages eligible for loading again.

func (*Pager[T]) SetFirst

func (p *Pager[T]) SetFirst(fn func(bool))

SetFirst observes the first page landing or failing.

func (*Pager[T]) SetLanded

func (p *Pager[T]) SetLanded(fn func(from int, items []T))

SetLanded observes pages as they land on the owner goroutine.

func (*Pager[T]) SetScope

func (p *Pager[T]) SetScope(ctx context.Context)

SetScope keeps loaded pages and detaches outstanding demand from the previous activation. Call it on the pager's owner goroutine.

func (*Pager[T]) Total

func (p *Pager[T]) Total() int

Total returns the known list length, or -1 until its first page lands.

func (*Pager[T]) When

func (p *Pager[T]) When(pg int, fn func(bool))

When calls fn once page pg is available, loading it if necessary.

func (*Pager[T]) Whole

func (p *Pager[T]) Whole(fn func(bool))

Whole invokes fn once all pages are loaded, or false if any page fails.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL