edelweiss
edelweiss copied to clipboard
Use iterators instead of channels on Async methods.
Instead of returning a channel for async methods, we should use iterators to avoid goroutines chains when using the API. We see a goroutine chain when we want to transform the channel type to another, needing a new channel and a new goroutine to process it.
Proposal
type Iterator struct {}
func (i *Iterator) Next()(AsyncReturn,error)
func (i *Iterator) HasNext() bool
Usage
for iter, err := o.getAsyncIterator(ctx,req); iter.HasNext(); {
if err != nil {
return err
}
value, err := iter.Next()
if err != nil {
return err
}
fmt.Println(value)
}