yield to chronos in mplex loop

This commit is contained in:
Dmitriy Ryajov 2019-09-25 14:12:42 -06:00
parent b5c4eaf9b8
commit f5508be544
2 changed files with 5 additions and 1 deletions

View File

@ -40,7 +40,7 @@ proc readMplexVarint(conn: Connection): Future[Option[uint]] {.async, gcsafe.} =
if res != VarintStatus.Success:
return
except LPStreamIncompleteError:
debug "unable to read varing", exc = getCurrentExceptionMsg()
trace "unable to read varint", exc = getCurrentExceptionMsg()
proc readMsg*(conn: Connection): Future[Option[Msg]] {.async, gcsafe.} =
let headerVarint = await conn.readMplexVarint()

View File

@ -57,6 +57,10 @@ method handle*(m: Mplex) {.async, gcsafe.} =
while not m.connection.closed:
let msgRes = await m.connection.readMsg()
if msgRes.isNone:
# TODO: this should ideally be poll(timeout = 100)
# but chronos poll() doesnt take a timeout, so it
# might and does hang
await sleepAsync(100.millis) # yield to async loop
continue
let (id, msgType, data) = msgRes.get()