Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Use iterators instead of channels on Async methods. #38

Open
ajnavarro opened this issue May 23, 2022 · 0 comments
Open

Use iterators instead of channels on Async methods. #38

ajnavarro opened this issue May 23, 2022 · 0 comments

Comments

@ajnavarro
Copy link
Member

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)
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant