don't await `nil` futures
This commit is contained in:
parent
deb46fef31
commit
480560c7c8
|
@ -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.} =
|
||||
|
|
Loading…
Reference in New Issue