Documentation
¶
Overview ¶
Package batch groups names by country and chunks them to the API's 100-per-request cap, then runs the requests with bounded concurrency while preserving input order. It is shared by the predict commands and enrich.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Item ¶
type Item struct {
Index int
Name string
Country string // normalized; "" means no country (always "" for nationality)
}
Item is one name carrying its original input index, which is the key used to restore output order regardless of completion order.
type Outcome ¶
Outcome is the result for one item, placed at outcomes[Item.Index]. Done is true only when the item's request succeeded; an item whose request was never scheduled (e.g. cancelled after a 429) has Done false and Err nil.
func RunRequests ¶
func RunRequests[T any]( ctx context.Context, reqs []Request, total int, concurrency int, fn func(context.Context, Request) ([]T, api.Quota, error), ) ([]Outcome[T], api.Quota, error)
RunRequests runs fn for each request with at most concurrency in flight, placing each item's result at outcomes[Item.Index] so input order is preserved. A 429 cancels remaining scheduling; other errors do not abort the run. The returned Quota is the freshest view (smallest Remaining seen) and the returned error is the first error encountered, if any.