Skip to content

Commit

Permalink
Refresh.
Browse files Browse the repository at this point in the history
  • Loading branch information
ptabor committed Dec 8, 2024
1 parent 9974e16 commit 13ed6b5
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions http/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,20 +335,26 @@ func (h *Handler) connectAll(w http.ResponseWriter, r *http.Request) {
}

func (h *Handler) connectAllInternal(iface string, waitSec string) error {
devices := h.discoverDnsEntries(context.Background(), iface, waitSec)
ctx := context.Background()
devices := h.discoverDnsEntries(ctx, iface, waitSec)
uuidMap := map[string]application.App{}
g, ctx := errgroup.WithContext(ctx)
for _, device := range devices {
app, err := h.connectInternal(device.Addr, device.Port, device.DeviceName)
if err != nil {
return err
}
uuidMap[device.UUID] = app
g.Go(func() error {
app, err := h.connectInternal(device.Addr, device.Port, device.DeviceName)
if err != nil {
return err
}
uuidMap[device.UUID] = app
return nil
})
}

err := g.Wait()
h.mu.Lock()
// Even if we cannot connect to some of the devices, we still update the map for remaining devices.
h.apps = uuidMap
h.mu.Unlock()
return nil
return err
}

func (h *Handler) disconnect(w http.ResponseWriter, r *http.Request) {
Expand Down

0 comments on commit 13ed6b5

Please sign in to comment.