@@ -108,12 +108,15 @@ template outgoingEvent(eventType: EventType): AsyncEvent =
108108 pool.outNotFullEvent
109109
110110proc waitForEvent [A, B](pool: PeerPool [A, B], eventType: EventType ,
111- filter: set [PeerType ]) {.async .} =
111+ filter: set [PeerType ]) {.async : (raises: [ CancelledError ]) .} =
112112 if filter == {PeerType .Incoming , PeerType .Outgoing } or filter == {}:
113113 var fut1 = incomingEvent (eventType).wait ()
114114 var fut2 = outgoingEvent (eventType).wait ()
115115 try :
116- discard await one (fut1, fut2)
116+ try :
117+ discard await one (fut1, fut2)
118+ except ValueError :
119+ raiseAssert " one precondition satisfied"
117120 if fut1.finished ():
118121 if not (fut2.finished ()):
119122 await fut2.cancelAndWait ()
@@ -138,11 +141,11 @@ proc waitForEvent[A, B](pool: PeerPool[A, B], eventType: EventType,
138141 outgoingEvent (eventType).clear ()
139142
140143proc waitNotEmptyEvent [A, B](pool: PeerPool [A, B],
141- filter: set [PeerType ]): Future [ void ] =
144+ filter: set [PeerType ]) {. async : (raises: [ CancelledError ], raw: true ).} =
142145 pool.waitForEvent (EventType .NotEmptyEvent , filter)
143146
144147proc waitNotFullEvent [A, B](pool: PeerPool [A, B],
145- filter: set [PeerType ]): Future [ void ] =
148+ filter: set [PeerType ]){. async : (raises: [ CancelledError ], raw: true ).} =
146149 pool.waitForEvent (EventType .NotFullEvent , filter)
147150
148151proc newPeerPool * [A, B](maxPeers = - 1 , maxIncomingPeers = - 1 ,
@@ -451,15 +454,15 @@ proc getPeerSpaceMask[A, B](pool: PeerPool[A, B],
451454 {PeerType .Outgoing }
452455
453456proc waitForEmptySpace * [A, B](pool: PeerPool [A, B],
454- peerType: PeerType ) {.async .} =
457+ peerType: PeerType ) {.async : (raises: [ CancelledError ]) .} =
455458 # # This procedure will block until ``pool`` will have an empty space for peer
456459 # # of type ``peerType``.
457460 let mask = pool.getPeerSpaceMask (peerType)
458461 while pool.lenSpace ({peerType}) == 0 :
459462 await pool.waitNotFullEvent (mask)
460463
461464proc 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 ]) .} =
463466 # # Add peer ``peer`` of type ``peerType`` to PeerPool ``pool``.
464467 # #
465468 # # This procedure will wait for an empty space in PeerPool ``pool``, if
@@ -533,7 +536,7 @@ proc acquireItemImpl[A, B](pool: PeerPool[A, B],
533536
534537proc acquire * [A, B](pool: PeerPool [A, B],
535538 filter = {PeerType .Incoming ,
536- PeerType .Outgoing }): Future [A] {.async .} =
539+ PeerType .Outgoing }): Future [A] {.async : (raises: [ CancelledError ]) .} =
537540 # # Acquire peer from PeerPool ``pool``, which match the filter ``filter``.
538541 mixin getKey
539542 doAssert (filter != {}, " Filter must not be empty" )
@@ -586,7 +589,7 @@ proc release*[A, B](pool: PeerPool[A, B], peers: openArray[A]) {.inline.} =
586589proc acquire * [A, B](pool: PeerPool [A, B],
587590 number: int ,
588591 filter = {PeerType .Incoming ,
589- PeerType .Outgoing }): Future [seq [A]] {.async .} =
592+ PeerType .Outgoing }): Future [seq [A]] {.async : (raises: [ CancelledError ]) .} =
590593 # # Acquire ``number`` number of peers from PeerPool ``pool``, which match the
591594 # # filter ``filter``.
592595 doAssert (filter != {}, " Filter must not be empty" )
@@ -735,7 +738,7 @@ proc clear*[A, B](pool: PeerPool[A, B]) =
735738 pool.acqIncPeersCount = 0
736739 pool.acqOutPeersCount = 0
737740
738- proc clearSafe * [A, B](pool: PeerPool [A, B]) {.async .} =
741+ proc clearSafe * [A, B](pool: PeerPool [A, B]) {.async : (raises: [ CancelledError ]) .} =
739742 # # Performs "safe" clear. Safe means that it first acquires all the peers
740743 # # in PeerPool, and only after that it will reset storage.
741744 var acquired = newSeq [A]()
0 commit comments