handle exception and remove unnecessary async
This commit is contained in:
parent
f682bb9171
commit
abe8c2489e
|
@ -335,8 +335,8 @@ proc canAskIWant*(p: PubSubPeer, msgId: MessageId): bool =
|
|||
return true
|
||||
return false
|
||||
|
||||
proc getMessage(rpcMessageQueue: RpcMessageQueue, p: PubSubPeer): Future[Opt[seq[byte]]] {.async.} =
|
||||
var m = await rpcMessageQueue.getPriorityMessage()
|
||||
proc getMessage(rpcMessageQueue: RpcMessageQueue, p: PubSubPeer): Opt[seq[byte]] =
|
||||
var m = rpcMessageQueue.getPriorityMessage()
|
||||
if m.isSome():
|
||||
when defined(libp2p_expensive_metrics):
|
||||
libp2p_gossipsub_priority_queue_size.dec(labelValues = [$p.peerId])
|
||||
|
@ -344,7 +344,7 @@ proc getMessage(rpcMessageQueue: RpcMessageQueue, p: PubSubPeer): Future[Opt[seq
|
|||
libp2p_gossipsub_priority_queue_size.dec(labelValues = [p.getAgent()])
|
||||
return m
|
||||
else:
|
||||
m = await rpcMessageQueue.getNonPriorityMessage()
|
||||
m = rpcMessageQueue.getNonPriorityMessage()
|
||||
if m.isSome():
|
||||
when defined(libp2p_expensive_metrics):
|
||||
libp2p_gossipsub_non_priority_queue_size.dec(labelValues = [$p.peerId])
|
||||
|
@ -356,7 +356,7 @@ proc getMessage(rpcMessageQueue: RpcMessageQueue, p: PubSubPeer): Future[Opt[seq
|
|||
|
||||
proc processMessages(p: PubSubPeer, queue: RpcMessageQueue) {.async.} =
|
||||
while true:
|
||||
let m = await queue.getMessage(p)
|
||||
let m = queue.getMessage(p)
|
||||
m.withValue(msg):
|
||||
if p.sendConn == nil:
|
||||
# Wait for a send conn to be setup. `connectOnce` will
|
||||
|
|
|
@ -29,16 +29,22 @@ proc new*(T: typedesc[RpcMessageQueue]): T =
|
|||
nonPriorityQueue: newAsyncQueue[seq[byte]]()
|
||||
)
|
||||
|
||||
proc getPriorityMessage*(rpcMessageQueue: RpcMessageQueue): Future[Opt[seq[byte]]] {.async.} =
|
||||
proc getPriorityMessage*(rpcMessageQueue: RpcMessageQueue): Opt[seq[byte]] =
|
||||
return
|
||||
if not rpcMessageQueue.priorityQueue.empty():
|
||||
Opt.some(rpcMessageQueue.priorityQueue.getNoWait())
|
||||
try:
|
||||
Opt.some(rpcMessageQueue.priorityQueue.getNoWait())
|
||||
except AsyncQueueEmptyError:
|
||||
Opt.none(seq[byte])
|
||||
else:
|
||||
Opt.none(seq[byte])
|
||||
|
||||
proc getNonPriorityMessage*(rpcMessageQueue: RpcMessageQueue): Future[Opt[seq[byte]]] {.async.} =
|
||||
proc getNonPriorityMessage*(rpcMessageQueue: RpcMessageQueue): Opt[seq[byte]] =
|
||||
return
|
||||
if not rpcMessageQueue.nonPriorityQueue.empty():
|
||||
Opt.some(rpcMessageQueue.nonPriorityQueue.getNoWait())
|
||||
try:
|
||||
Opt.some(rpcMessageQueue.nonPriorityQueue.getNoWait())
|
||||
except AsyncQueueEmptyError:
|
||||
Opt.none(seq[byte])
|
||||
else:
|
||||
Opt.none(seq[byte])
|
||||
|
|
Loading…
Reference in New Issue