More proper client closing code

This commit is contained in:
Zahary Karadjov 2021-04-06 21:48:32 +03:00 committed by zah
parent 64d40d6c1a
commit 7a9d118929
2 changed files with 8 additions and 3 deletions

View File

@ -63,5 +63,7 @@ proc connect*(client: RpcSocketClient, address: string, port: Port) {.async.} =
client.loop = processData(client)
method close*(client: RpcSocketClient) {.async.} =
# TODO: Stop the processData loop
await client.transport.closeWait()
await client.loop.cancelAndWait()
if not client.transport.isNil:
client.transport.close()
client.transport = nil

View File

@ -78,5 +78,8 @@ proc connect*(client: RpcWebSocketClient, uri: string, headers: StringTableRef =
client.loop = processData(client)
method close*(client: RpcWebSocketClient) {.async.} =
await client.loop.cancelAndWait()
if not client.transport.isNil:
client.loop.cancel()
client.transport.close()
client.transport = nil