diff options
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/client/gateway/gateway.go | 5 | ||||
| -rw-r--r-- | internal/client/ui/core/core.go | 14 |
2 files changed, 18 insertions, 1 deletions
diff --git a/internal/client/gateway/gateway.go b/internal/client/gateway/gateway.go index 4d7c9ed..c8824fd 100644 --- a/internal/client/gateway/gateway.go +++ b/internal/client/gateway/gateway.go @@ -239,13 +239,16 @@ func Send(request packet.Payload) tea.Cmd { } } -func SendAsync(request packet.Payload) { +func SendAsync(request packet.Payload) <-chan error { + ch := make(chan error, 1) go func() { err := send(request) if err != nil { log.Println("async request send error:", err) } + ch <- err }() + return ch } func send(request packet.Payload) error { diff --git a/internal/client/ui/core/core.go b/internal/client/ui/core/core.go index 4aa5d5d..1ba0069 100644 --- a/internal/client/ui/core/core.go +++ b/internal/client/ui/core/core.go @@ -1,6 +1,7 @@ package core import ( + "context" "crypto/ed25519" "fmt" "log" @@ -258,6 +259,19 @@ func (m *Model) updateConnected(msg tea.Msg) tea.Cmd { switch msg := msg.(type) { case ui.QuitMsg: + data := state.JsonUserData() + ch := gateway.SendAsync(&packet.SetUserData{ + Data: &data, + User: nil, + }) + + ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) + select { + case <-ctx.Done(): + case <-ch: + } + cancel() + gateway.Disconnect() case gateway.ConnectionLost: |
