traversal

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: MIT Imports: 4 Imported by: 0 modules, 0 packages

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

Overview

Package traversal 提供可由调用方重放的通用逻辑分页遍历。

本包只处理 execute 生命周期、分页计划和 opaque cursor,不负责账号选择、 网络策略、过滤语义或任何具体产品的错误映射。

Index

Constants

This section is empty.

Variables

View Source
var ErrExecuteNotConfigured = errors.New("traversal: execute function is not configured")

ErrExecuteNotConfigured 表示调用方没有提供可重放的 execute 函数。 产品 owner 可将它映射为自己的稳定错误类型。

Functions

func TraverseWith

func TraverseWith[C any, T any](
	ctx context.Context,
	execute Execute[C],
	plan pagination.PagePlan,
	begin func() error,
	fetch func(context.Context, C, sdk.Cursor) ([]T, sdk.Cursor, error),
	consume func([]T) (committed bool, err error),
) (pagination.PageResult, error)

TraverseWith 在 execute 提供的重放边界内执行一次逻辑分页遍历。

begin 会在每次 execute 尝试开始时调用。consume 返回 committed=true 时, execute owner 可以据此禁止后续重放。分页引擎仍由 shared/pagination 负责 Skip、Limit、OneBatch、cursor 循环检测和 HasMore 语义。返回的 PageResult 携带引擎权威的 Returned 与 HasMore,包括上游批次内被 Limit 截断但上游 cursor 已为空的情形——此时仍有未返回的条目,HasMore 必须为 true。

Types

type Execute

type Execute[C any] func(context.Context, func(context.Context, C) (committed bool, err error)) error

Execute 在调用方提供的可重放边界内使用一次资源。 committed=true 表示本次尝试已经越过交付或副作用边界。

type PagedReadResult

type PagedReadResult[T any] struct {
	Items   []T
	HasMore bool
}

PagedReadResult 是逻辑分页结果;opaque cursor 不离开 traversal。

func CollectWith

func CollectWith[C any, T any](
	ctx context.Context,
	execute Execute[C],
	plan pagination.PagePlan,
	fetch func(context.Context, C, sdk.Cursor) ([]T, sdk.Cursor, error),
) (PagedReadResult[T], error)

CollectWith 在 execute 提供的重放边界内收集逻辑分页结果。 每次新尝试开始时都会清空前一次未提交的结果,避免重放时混入不同资源 的数据;失败时返回当前尝试的结果和原始错误。

Jump to

Keyboard shortcuts

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