package commands import ( "context" "errors" "git.loyso.art/frx/eway/internal/entity" ) type chanIter[T any] struct { in <-chan T err error next T } var errChannelClosed = errors.New("channel closed") func (i *chanIter[T]) Next() (ok bool) { if i.err != nil { return false } i.next, ok = <-i.in if !ok { i.err = errChannelClosed } return ok } func (i *chanIter[T]) Get() T { return i.next } func (i *chanIter[T]) Err() error { if errors.Is(i.err, errChannelClosed) { return nil } return i.err } func (i *chanIter[T]) Close() { for range i.in { } } func getItemsIter(ctx context.Context, r entity.GoodsItemRepository) *chanIter[entity.GoodsItem] { in, err := r.ListIter(ctx, 3) return &chanIter[entity.GoodsItem]{ in: in, err: err, } }