don't await `nil` futures
This commit is contained in:
parent
deb46fef31
commit
480560c7c8
|
@ -93,7 +93,7 @@ proc send*(
|
||||||
ws: WSSession,
|
ws: WSSession,
|
||||||
data: seq[byte] = @[],
|
data: seq[byte] = @[],
|
||||||
opcode: Opcode): Future[void]
|
opcode: Opcode): Future[void]
|
||||||
{.raises: [Defect, WSClosedError].} =
|
{.async, raises: [Defect, WSClosedError].} =
|
||||||
## Send a frame
|
## Send a frame
|
||||||
##
|
##
|
||||||
|
|
||||||
|
@ -117,9 +117,12 @@ proc send*(
|
||||||
default(MaskKey)
|
default(MaskKey)
|
||||||
|
|
||||||
if opcode in {Opcode.Text, Opcode.Cont, Opcode.Binary}:
|
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*(
|
proc send*(
|
||||||
ws: WSSession,
|
ws: WSSession,
|
||||||
|
@ -389,7 +392,6 @@ proc recv*(
|
||||||
if not ws.binary and validateUTF8(pbuffer.toOpenArray(0, consumed - 1)) == false:
|
if not ws.binary and validateUTF8(pbuffer.toOpenArray(0, consumed - 1)) == false:
|
||||||
raise newException(WSInvalidUTF8, "Invalid UTF8 sequence detected")
|
raise newException(WSInvalidUTF8, "Invalid UTF8 sequence detected")
|
||||||
|
|
||||||
return consumed
|
|
||||||
except CatchableError as exc:
|
except CatchableError as exc:
|
||||||
trace "Exception reading frames", exc = exc.msg
|
trace "Exception reading frames", exc = exc.msg
|
||||||
ws.readyState = ReadyState.Closed
|
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"
|
trace "Last frame in message and no more bytes left to read, reseting current frame"
|
||||||
ws.frame = nil
|
ws.frame = nil
|
||||||
|
|
||||||
|
return consumed
|
||||||
|
|
||||||
proc recv*(
|
proc recv*(
|
||||||
ws: WSSession,
|
ws: WSSession,
|
||||||
size = WSMaxMessageSize): Future[seq[byte]] {.async.} =
|
size = WSMaxMessageSize): Future[seq[byte]] {.async.} =
|
||||||
|
|
Loading…
Reference in New Issue