Skip to content

Commit 4796356

Browse files
committed
Factored subrotuine into a function
it will be useful in the next commits.
1 parent d4f7a2f commit 4796356

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

arduino/discovery/discoverymanager/discoverymanager.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -200,24 +200,28 @@ func (dm *DiscoveryManager) feedEvent(ev *discovery.Event) {
200200
dm.watchersMutex.Lock()
201201
defer dm.watchersMutex.Unlock()
202202

203+
sendToAllWatchers := func(ev *discovery.Event) {
204+
// Send the event to all watchers
205+
for watcher := range dm.watchers {
206+
select {
207+
case watcher.feed <- ev:
208+
// OK
209+
case <-time.After(time.Millisecond * 500):
210+
// If the watcher is not able to process event fast enough
211+
// remove the watcher from the list of watchers
212+
logrus.Info("Watcher is not able to process events fast enough, removing it from the list of watchers")
213+
delete(dm.watchers, watcher)
214+
}
215+
}
216+
}
217+
203218
if ev.Type == "stop" {
204219
// Remove all the cached events for the terminating discovery
205220
delete(dm.watchersCache, ev.DiscoveryID)
206221
return
207222
}
208223

209-
// Send the event to all watchers
210-
for watcher := range dm.watchers {
211-
select {
212-
case watcher.feed <- ev:
213-
// OK
214-
case <-time.After(time.Millisecond * 500):
215-
// If the watcher is not able to process event fast enough
216-
// remove the watcher from the list of watchers
217-
logrus.Info("Watcher is not able to process events fast enough, removing it from the list of watchers")
218-
delete(dm.watchers, watcher)
219-
}
220-
}
224+
sendToAllWatchers(ev)
221225

222226
// Cache the event for the discovery
223227
cache := dm.watchersCache[ev.DiscoveryID]

0 commit comments

Comments
 (0)