Skip to content

Commit 9d7fb5c

Browse files
committed
use ch.Collect in module
1 parent 8cc15f8 commit 9d7fb5c

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

mod/services/src/module.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,8 @@ func (mod *Module) DiscoverRemoteServices(ctx *astral.Context, target *astral.Id
6060
snapshotCompleted := false
6161
snapshot := make([]services.ServiceChange, 0)
6262

63-
for {
64-
msg, err := ch.Read()
65-
if err != nil {
66-
return err
67-
}
68-
69-
switch m := msg.(type) {
63+
err = ch.Collect(func(object astral.Object) error {
64+
switch m := object.(type) {
7065
case *astral.EOS:
7166
// End-of-snapshot marker.
7267

@@ -105,13 +100,13 @@ func (mod *Module) DiscoverRemoteServices(ctx *astral.Context, target *astral.Id
105100
case *services.ServiceChange:
106101
if !m.Service.Identity.IsEqual(target) {
107102
mod.log.Info("ignoring service from different identity: %v", m.Service.Identity)
108-
continue
103+
return nil
109104
}
110105

111106
if !snapshotCompleted {
112107
// Still collecting snapshot.
113108
snapshot = append(snapshot, *m)
114-
continue
109+
return nil
115110
}
116111

117112
// Live update after snapshot completed.
@@ -131,7 +126,14 @@ func (mod *Module) DiscoverRemoteServices(ctx *astral.Context, target *astral.Id
131126
}
132127

133128
default:
134-
mod.log.Info("unexpected message type: %T", msg)
129+
mod.log.Info("unexpected message type: %T", object)
135130
}
131+
132+
return nil
133+
})
134+
if err != nil {
135+
return err
136136
}
137+
138+
return nil
137139
}

0 commit comments

Comments
 (0)