update queue for max performance
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 2m1s
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 2m1s
This commit is contained in:
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
@@ -91,13 +92,15 @@ func (m *CartTCPClient) SendPacket(messageType uint32, id CartId, data []byte) e
|
||||
// }
|
||||
|
||||
func (m *CartTCPClient) Call(messageType uint32, id CartId, responseType uint32, data []byte) ([]byte, error) {
|
||||
packetChan := m.Expect(responseType, id)
|
||||
err := m.SendPacket(messageType, id, data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
packet, err := m.Expect(responseType, id, time.Second)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
select {
|
||||
case ret := <-packetChan:
|
||||
return ret, nil
|
||||
case <-time.After(3 * time.Second):
|
||||
return nil, fmt.Errorf("timeout")
|
||||
}
|
||||
return packet.Data, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user