Use closeWait

This commit is contained in:
Yuriy Glukhov 2019-06-17 19:56:19 +03:00
parent ac2f6b9360
commit b583dfb029
5 changed files with 7 additions and 7 deletions

View File

@ -28,7 +28,7 @@ proc rpcCallNode*(path: string, params: JsonNode, id: ClientId): JsonNode =
method call*(client: RpcClient, name: string,
params: JsonNode): Future[Response] {.async, base.} = discard
method close*(client: RpcClient) {.base.} = discard
method close*(client: RpcClient) {.base, async.} = discard
template asyncRaise[T](fut: Future[T], errType: typedesc, msg: string) =
fut.fail(newException(errType, msg))

View File

@ -183,7 +183,7 @@ method call*(client: RpcHttpClient, name: string,
if not res:
debug "Failed to send message to RPC server",
address = transp.remoteAddress(), msg_len = len(reqBody)
transp.close()
await transp.closeWait()
raise newException(ValueError, "Transport error")
else:
debug "Message sent to RPC server", address = transp.remoteAddress(),
@ -191,7 +191,7 @@ method call*(client: RpcHttpClient, name: string,
trace "Message", msg = reqBody
var value = await transp.recvData()
transp.close()
await transp.closeWait()
if value.len == 0:
raise newException(ValueError, "Empty response from server")

View File

@ -50,6 +50,6 @@ proc connect*(client: RpcSocketClient, address: string, port: Port) {.async.} =
client.address = addresses[0]
client.loop = processData(client)
method close*(client: RpcSocketClient) =
method close*(client: RpcSocketClient) {.async.} =
# TODO: Stop the processData loop
client.transport.close()
await client.transport.closeWait()

View File

@ -49,6 +49,6 @@ proc connect*(client: RpcWebSocketClient, uri: string) {.async.} =
client.uri = uri
client.loop = processData(client)
method close*(client: RpcWebSocketClient) =
method close*(client: RpcWebSocketClient) {.async.} =
# TODO: Stop the processData loop
client.transport.close()

View File

@ -66,7 +66,7 @@ proc continuousTest(address: string, port: Port): Future[int] {.async.} =
var r = await client.call("myProc", %[%"abc", %[1, 2, 3, i]])
if r.result.getStr == "Hello abc data: [1, 2, 3, " & $i & "]":
result += 1
client.close()
await client.close()
proc customMessage(address: TransportAddress,
data: string,