From: Jeff Halter Date: Mon, 21 Nov 2022 17:10:24 +0000 (-0800) Subject: Minor improvements to sendTransaction X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/commitdiff_plain/75e4191b32b72ab4ac8e267c274f37769f95c995 Minor improvements to sendTransaction 1. Remove use of defer for the unlock because it make hold the mutex longer than necessary 2. Remove shadowed err var on L166 --- diff --git a/hotline/server.go b/hotline/server.go index e28ff9a..1aa9b1a 100644 --- a/hotline/server.go +++ b/hotline/server.go @@ -152,8 +152,8 @@ func (s *Server) sendTransaction(t Transaction) error { } s.mux.Lock() - defer s.mux.Unlock() client := s.Clients[uint16(clientID)] + s.mux.Unlock() if client == nil { return fmt.Errorf("invalid client id %v", *t.clientID) } @@ -163,7 +163,8 @@ func (s *Server) sendTransaction(t Transaction) error { return err } - if _, err := client.Connection.Write(b); err != nil { + _, err = client.Connection.Write(b) + if err != nil { return err }