Files
yatm/internal/executor/copy_pages.go
T
Samuel Cui 4fef653b71 Prepare YATM v1.0.0-alpha.2
Unify file queries and Scan execution, retain indexed Identical results,
improve Job and Preview workflows, and verify release packaging.
2026-10-05 19:08:49 +08:00

35 lines
820 B
Go

package executor
import (
"context"
"errors"
"io"
"github.com/samuelncui/acp"
)
// RunCopyPages feeds bounded caller-owned pages and always drains accepted ACP work.
// Callers own item policy and must drain their result writer after this returns.
func RunCopyPages(ctx context.Context, engine *acp.StreamCopyer, next func(context.Context) ([]acp.Item, error)) (rerr error) {
// Wait owns pipeline failures; linear target exhaustion may be reported only by Submit.
defer func() {
closeErr := engine.Close()
if waitErr := engine.Wait(); waitErr != nil {
rerr = waitErr
}
rerr = errors.Join(rerr, closeErr)
}()
for {
items, err := next(ctx)
if errors.Is(err, io.EOF) {
return nil
}
if err != nil {
return err
}
if err := engine.Submit(items...); err != nil {
return err
}
}
}