mirror of https://github.com/vacp2p/nim-libp2p.git
yield to chronos in mplex loop
This commit is contained in:
parent
b5c4eaf9b8
commit
f5508be544
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue