minor rework and filter dimensions

This commit is contained in:
Aleksandr Trushkin
2024-02-13 21:19:39 +03:00
parent 23a4f007fc
commit 8f26b8ba6d
13 changed files with 969 additions and 780 deletions

View File

@ -0,0 +1,55 @@
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,
}
}