From 480560c7c8de9952668d18aef33995fa8d78158d Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Fri, 11 Jun 2021 20:53:34 -0600 Subject: [PATCH] don't await `nil` futures --- ws/session.nim | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ws/session.nim b/ws/session.nim index 904ab2d8..289d4e1b 100644 --- a/ws/session.nim +++ b/ws/session.nim @@ -93,7 +93,7 @@ proc send*( ws: WSSession, data: seq[byte] = @[], opcode: Opcode): Future[void] - {.raises: [Defect, WSClosedError].} = + {.async, raises: [Defect, WSClosedError].} = ## Send a frame ## @@ -117,9 +117,12 @@ proc send*( default(MaskKey) if opcode in {Opcode.Text, Opcode.Cont, Opcode.Binary}: - return ws.writeMessage(data, opcode, maskKey, ws.extensions) + await ws.writeMessage( + data, opcode, maskKey, ws.extensions) - return ws.writeControl(data, opcode, maskKey) + return + + await ws.writeControl(data, opcode, maskKey) proc send*( ws: WSSession, @@ -389,7 +392,6 @@ proc recv*( if not ws.binary and validateUTF8(pbuffer.toOpenArray(0, consumed - 1)) == false: raise newException(WSInvalidUTF8, "Invalid UTF8 sequence detected") - return consumed except CatchableError as exc: trace "Exception reading frames", exc = exc.msg ws.readyState = ReadyState.Closed @@ -402,6 +404,8 @@ proc recv*( trace "Last frame in message and no more bytes left to read, reseting current frame" ws.frame = nil + return consumed + proc recv*( ws: WSSession, size = WSMaxMessageSize): Future[seq[byte]] {.async.} =