@@ -108,12 +108,15 @@ template outgoingEvent(eventType: EventType): AsyncEvent =
108
108
pool.outNotFullEvent
109
109
110
110
proc waitForEvent[A, B](pool: PeerPool[A, B], eventType: EventType,
111
- filter: set [PeerType]) {.async.} =
111
+ filter: set [PeerType]) {.async: (raises: [CancelledError]) .} =
112
112
if filter == {PeerType.Incoming, PeerType.Outgoing} or filter == {}:
113
113
var fut1 = incomingEvent(eventType).wait()
114
114
var fut2 = outgoingEvent(eventType).wait()
115
115
try:
116
- discard await one(fut1, fut2)
116
+ try:
117
+ discard await one(fut1, fut2)
118
+ except ValueError:
119
+ raiseAssert "one precondition satisfied"
117
120
if fut1.finished():
118
121
if not(fut2.finished()):
119
122
await fut2.cancelAndWait()
@@ -138,11 +141,11 @@ proc waitForEvent[A, B](pool: PeerPool[A, B], eventType: EventType,
138
141
outgoingEvent(eventType).clear()
139
142
140
143
proc waitNotEmptyEvent[A, B](pool: PeerPool[A, B],
141
- filter: set [PeerType]): Future[ void ] =
144
+ filter: set [PeerType]) {.async: (raises: [CancelledError], raw: true).} =
142
145
pool.waitForEvent(EventType.NotEmptyEvent, filter)
143
146
144
147
proc waitNotFullEvent[A, B](pool: PeerPool[A, B],
145
- filter: set [PeerType]): Future[ void ] =
148
+ filter: set [PeerType]){.async: (raises: [CancelledError], raw: true).} =
146
149
pool.waitForEvent(EventType.NotFullEvent, filter)
147
150
148
151
proc newPeerPool*[A, B](maxPeers = -1, maxIncomingPeers = -1,
@@ -451,15 +454,15 @@ proc getPeerSpaceMask[A, B](pool: PeerPool[A, B],
451
454
{PeerType.Outgoing}
452
455
453
456
proc waitForEmptySpace*[A, B](pool: PeerPool[A, B],
454
- peerType: PeerType) {.async.} =
457
+ peerType: PeerType) {.async: (raises: [CancelledError]) .} =
455
458
## This procedure will block until ``pool`` will have an empty space for peer
456
459
## of type ``peerType``.
457
460
let mask = pool.getPeerSpaceMask(peerType)
458
461
while pool.lenSpace({peerType}) == 0:
459
462
await pool.waitNotFullEvent(mask)
460
463
461
464
proc addPeer*[A, B](pool: PeerPool[A, B],
462
- peer: A, peerType: PeerType): Future[PeerStatus] {.async.} =
465
+ peer: A, peerType: PeerType): Future[PeerStatus] {.async: (raises: [CancelledError]) .} =
463
466
## Add peer ``peer`` of type ``peerType`` to PeerPool ``pool``.
464
467
##
465
468
## This procedure will wait for an empty space in PeerPool ``pool``, if
@@ -533,7 +536,7 @@ proc acquireItemImpl[A, B](pool: PeerPool[A, B],
533
536
534
537
proc acquire* [A, B](pool: PeerPool[A, B],
535
538
filter = {PeerType.Incoming,
536
- PeerType.Outgoing}): Future[A] {.async.} =
539
+ PeerType.Outgoing}): Future[A] {.async: (raises: [CancelledError]) .} =
537
540
## Acquire peer from PeerPool ``pool``, which match the filter ``filter``.
538
541
mixin getKey
539
542
doAssert(filter != {}, "Filter must not be empty")
@@ -586,7 +589,7 @@ proc release*[A, B](pool: PeerPool[A, B], peers: openArray[A]) {.inline.} =
586
589
proc acquire*[A, B](pool: PeerPool[A, B],
587
590
number: int ,
588
591
filter = {PeerType.Incoming,
589
- PeerType.Outgoing}): Future[seq [A]] {.async.} =
592
+ PeerType.Outgoing}): Future[seq [A]] {.async: (raises: [CancelledError]) .} =
590
593
## Acquire ``number`` number of peers from PeerPool ``pool``, which match the
591
594
## filter ``filter``.
592
595
doAssert(filter != {}, "Filter must not be empty")
@@ -735,7 +738,7 @@ proc clear*[A, B](pool: PeerPool[A, B]) =
735
738
pool.acqIncPeersCount = 0
736
739
pool.acqOutPeersCount = 0
737
740
738
- proc clearSafe*[A, B](pool: PeerPool[A, B]) {.async.} =
741
+ proc clearSafe*[A, B](pool: PeerPool[A, B]) {.async: (raises: [CancelledError]) .} =
739
742
## Performs "safe" clear. Safe means that it first acquires all the peers
740
743
## in PeerPool, and only after that it will reset storage.
741
744
var acquired = newSeq[A]()
0 commit comments