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"
|
||||
)
|
||||
@@ -94,13 +95,16 @@ func (m *TCPClient) SendPacket(messageType uint32, data []byte) error {
|
||||
// }
|
||||
|
||||
func (m *TCPClient) Call(messageType uint32, responseType uint32, data []byte) ([]byte, error) {
|
||||
packetChan := m.Expect(responseType)
|
||||
err := m.SendPacket(messageType, data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
packet, err := m.Expect(responseType, 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