Fixed race condition when rpc server responds too fast

This commit is contained in:
Yuriy Glukhov 2019-06-26 13:39:58 +03:00
parent 48699c50ca
commit 4bb08c671b
2 changed files with 7 additions and 4 deletions

View File

@ -21,14 +21,16 @@ method call*(self: RpcSocketClient, name: string,
if self.transport.isNil:
raise newException(ValueError,
"Transport is not initialised (missing a call to connect?)")
let res = await self.transport.write(value)
# TODO: Add actions when not full packet was send, e.g. disconnect peer.
doAssert(res == len(value))
# completed by processMessage.
var newFut = newFuture[Response]()
# add to awaiting responses
self.awaiting[id] = newFut
let res = await self.transport.write(value)
# TODO: Add actions when not full packet was send, e.g. disconnect peer.
doAssert(res == len(value))
result = await newFut
proc processData(client: RpcSocketClient) {.async.} =

View File

@ -23,12 +23,13 @@ method call*(self: RpcWebSocketClient, name: string,
raise newException(ValueError,
"Transport is not initialised (missing a call to connect?)")
# echo "Sent msg: ", value
await self.transport.send(value)
# completed by processMessage.
var newFut = newFuture[Response]()
# add to awaiting responses
self.awaiting[id] = newFut
await self.transport.send(value)
result = await newFut
proc processData(client: RpcWebSocketClient) {.async.} =