prevent already closed errors

This commit is contained in:
Dmitriy Ryajov 2019-09-03 19:41:28 -06:00
parent 8549ce76bb
commit cc26d4e040
1 changed files with 9 additions and 5 deletions

View File

@ -55,10 +55,14 @@ method write*(s: ChronosStream, msg: seq[byte], msglen = -1) {.async, gcsafe.} =
await s.writer.write(msg, msglen) await s.writer.write(msg, msglen)
method close*(s: ChronosStream) {.async, gcsafe.} = method close*(s: ChronosStream) {.async, gcsafe.} =
await s.reader.closeWait() if not s.closed:
if not s.reader.closed:
await s.reader.closeWait()
await s.writer.finish() await s.writer.finish()
await s.writer.closeWait()
await s.client.closeWait() if not s.writer.closed:
s.closed = true await s.writer.closeWait()
await s.client.closeWait()
s.closed = true