zones: allow iterators to terminate

Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
2023-08-22 20:11:41 +00:00
parent 589fb2f0e1
commit f7da9519fa
2 changed files with 13 additions and 8 deletions
+3 -4
View File
@@ -31,10 +31,9 @@ func (m *Zones) scan() error {
func (m *Zones) scanMachines() error {
var err error
m.ForEachMachine(func(p *Machine) {
if err == nil {
err = p.scan()
}
m.ForEachMachine(func(p *Machine) bool {
err = p.scan()
return err != nil
})
return err
}
+10 -4
View File
@@ -32,18 +32,24 @@ type Zones struct {
}
// ForEachMachine calls a function for each Machine in the cluster
func (m *Zones) ForEachMachine(fn func(*Machine)) {
func (m *Zones) ForEachMachine(fn func(*Machine) bool) {
for _, z := range m.Zones {
for _, p := range z.Machines {
fn(p)
if fn(p) {
// terminate
return
}
}
}
}
// ForEachZone calls a function for each Zone in the cluster
func (m *Zones) ForEachZone(fn func(*Zone)) {
func (m *Zones) ForEachZone(fn func(*Zone) bool) {
for _, p := range m.Zones {
fn(p)
if fn(p) {
// terminate
return
}
}
}