Skip to content

Commit

Permalink
Merge pull request #57 from chaitin/fix(iterator)/reset
Browse files Browse the repository at this point in the history
fix(iterator): reset
  • Loading branch information
zhoubinxuan authored Jan 13, 2023
2 parents e56ed5a + 17d487a commit 611bbf7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions go/cmd/iac.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ func ScanIACs(
}

uniq.Range(func(key, value interface{}) bool {
// Reset iterator for next objects
defer iter.Reset()

t := key.(iac.IACType)
if paths, ok := value.([]string); ok {
if err = plugin.Exec(ctx, iter, paths,
Expand Down
3 changes: 3 additions & 0 deletions go/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ func Scan(
}
var err error
result.Range(func(_, val interface{}) bool {
// Reset iterator for next objects
defer iter.Reset()

p := val.(*partition)
if err = plugin.Exec(ctx, iter, p.ids,
plugin.WithPrependArgs("--mode", p.root.Mode()),
Expand Down
10 changes: 10 additions & 0 deletions go/plugin/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type ExecIterator interface {
HasNext() bool
Next() (*Plugin, *Command, error)
Done()
Reset()
}

type pluginIterator struct {
Expand Down Expand Up @@ -43,6 +44,11 @@ func (p *pluginIterator) Next() (*Plugin, *Command, error) {
return plug, cmd, nil
}

func (p *pluginIterator) Reset() {
p.i = 0
p.j = 0
}

func (p *pluginIterator) Done() {
}

Expand All @@ -66,6 +72,10 @@ func (f *filterIterator) Next() (*Plugin, *Command, error) {
return nil, nil, nil
}

func (f *filterIterator) Reset() {
f.iter.Reset()
}

func (f *filterIterator) Done() {
f.iter.Done()
}
Expand Down

0 comments on commit 611bbf7

Please sign in to comment.