Skip to content

Commit 5330736

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

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
@@ -198,24 +198,28 @@ func (dm *DiscoveryManager) feedEvent(ev *discovery.Event) {
198198
dm.watchersMutex.Lock()
199199
defer dm.watchersMutex.Unlock()
200200

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

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

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

0 commit comments

Comments
 (0)