mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-01-23 10:35:44 +00:00
Fix possibility of lost IDs for WS requests/responses
This commit is contained in:
parent
21a2680027
commit
3076be593e
1 changed files with 3 additions and 2 deletions
|
|
@ -96,7 +96,8 @@ func (c *Client) Close() {
|
|||
func (c *Client) Call(type_ api.PT, payload any) ([]byte, error) {
|
||||
// !to expose channel instead of results
|
||||
rq := outPool.Get().(*Out)
|
||||
rq.Id, rq.T, rq.Payload = network.NewUid(), type_, payload
|
||||
id := network.NewUid()
|
||||
rq.Id, rq.T, rq.Payload = id, type_, payload
|
||||
r, err := json.Marshal(rq)
|
||||
outPool.Put(rq)
|
||||
if err != nil {
|
||||
|
|
@ -106,7 +107,7 @@ func (c *Client) Call(type_ api.PT, payload any) ([]byte, error) {
|
|||
|
||||
task := &call{done: make(chan struct{})}
|
||||
c.mu.Lock()
|
||||
c.queue[rq.Id] = task
|
||||
c.queue[id] = task
|
||||
c.conn.Write(r)
|
||||
c.mu.Unlock()
|
||||
select {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue