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:
|
if res != VarintStatus.Success:
|
||||||
return
|
return
|
||||||
except LPStreamIncompleteError:
|
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.} =
|
proc readMsg*(conn: Connection): Future[Option[Msg]] {.async, gcsafe.} =
|
||||||
let headerVarint = await conn.readMplexVarint()
|
let headerVarint = await conn.readMplexVarint()
|
||||||
|
|
|
@ -57,6 +57,10 @@ method handle*(m: Mplex) {.async, gcsafe.} =
|
||||||
while not m.connection.closed:
|
while not m.connection.closed:
|
||||||
let msgRes = await m.connection.readMsg()
|
let msgRes = await m.connection.readMsg()
|
||||||
if msgRes.isNone:
|
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
|
continue
|
||||||
|
|
||||||
let (id, msgType, data) = msgRes.get()
|
let (id, msgType, data) = msgRes.get()
|
||||||
|
|
Loading…
Reference in New Issue