mirror of
https://github.com/logos-storage/nim-json-rpc.git
synced 2026-01-10 09:33:06 +00:00
Use closeWait
This commit is contained in:
parent
ac2f6b9360
commit
b583dfb029
@ -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))
|
||||
|
||||
@ -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")
|
||||
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user