diff --git a/json_rpc/client.nim b/json_rpc/client.nim index 464ba66..59e9e32 100644 --- a/json_rpc/client.nim +++ b/json_rpc/client.nim @@ -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)) diff --git a/json_rpc/clients/httpclient.nim b/json_rpc/clients/httpclient.nim index 595159e..929a2ae 100644 --- a/json_rpc/clients/httpclient.nim +++ b/json_rpc/clients/httpclient.nim @@ -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") diff --git a/json_rpc/clients/socketclient.nim b/json_rpc/clients/socketclient.nim index 593bff3..1a8064a 100644 --- a/json_rpc/clients/socketclient.nim +++ b/json_rpc/clients/socketclient.nim @@ -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() diff --git a/json_rpc/clients/websocketclient.nim b/json_rpc/clients/websocketclient.nim index b1d59d9..714e147 100644 --- a/json_rpc/clients/websocketclient.nim +++ b/json_rpc/clients/websocketclient.nim @@ -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() diff --git a/tests/testhttp.nim b/tests/testhttp.nim index d588ebc..04c9dca 100644 --- a/tests/testhttp.nim +++ b/tests/testhttp.nim @@ -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,