Skip to content

Commit

Permalink
More proper client closing code
Browse files Browse the repository at this point in the history
  • Loading branch information
zah committed Apr 6, 2021
1 parent 64d40d6 commit 7a9d118
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 4 additions & 2 deletions json_rpc/clients/socketclient.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion json_rpc/clients/websocketclient.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7a9d118

Please sign in to comment.