mirror of
https://github.com/netbirdio/netbird.git
synced 2026-05-18 14:49:57 +00:00
[client/ui] Remove goroutine from ProfileSwitcher.SwitchActive
Down and Up(async=true) are both fast RPCs; no background goroutine is needed. SwitchActive is now fully synchronous — the tray wraps the call in its own goroutine, and Wails handles React calls similarly.
This commit is contained in:
@@ -62,25 +62,21 @@ func (s *ProfileSwitcher) SwitchActive(ctx context.Context, p ProfileRef) error
|
|||||||
return fmt.Errorf("switch profile %q: %w", p.ProfileName, err)
|
return fmt.Errorf("switch profile %q: %w", p.ProfileName, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Down and Up run in a goroutine so the caller returns immediately after
|
if needsDown {
|
||||||
// the Switch RPC. Up uses async mode so the goroutine itself is short-lived.
|
if err := s.connection.Down(ctx); err != nil {
|
||||||
go func() {
|
log.Errorf("profileswitcher: Down: %v", err)
|
||||||
bgCtx := context.Background()
|
|
||||||
if needsDown {
|
|
||||||
if err := s.connection.Down(bgCtx); err != nil {
|
|
||||||
log.Errorf("profileswitcher: Down: %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if wasActive {
|
}
|
||||||
if err := s.connection.Up(bgCtx, UpParams{
|
|
||||||
ProfileName: p.ProfileName,
|
if wasActive {
|
||||||
Username: p.Username,
|
if err := s.connection.Up(ctx, UpParams{
|
||||||
Async: true,
|
ProfileName: p.ProfileName,
|
||||||
}); err != nil {
|
Username: p.Username,
|
||||||
log.Errorf("profileswitcher: Up %s: %v", p.ProfileName, err)
|
Async: true,
|
||||||
}
|
}); err != nil {
|
||||||
|
return fmt.Errorf("reconnect %q: %w", p.ProfileName, err)
|
||||||
}
|
}
|
||||||
}()
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user