edelweiss icon indicating copy to clipboard operation
edelweiss copied to clipboard

Use iterators instead of channels on Async methods.

Open ajnavarro opened this issue 3 years ago • 0 comments

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)
}

ajnavarro avatar May 23 '22 08:05 ajnavarro