File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
crates/nostr-sdk/src/relay Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -1559,6 +1559,45 @@ impl Relay {
15591559 } ) ;
15601560 }
15611561
1562+ /// Count events of filters
1563+ pub async fn count_events_of (
1564+ & self ,
1565+ filters : Vec < Filter > ,
1566+ timeout : Duration ,
1567+ ) -> Result < usize , Error > {
1568+ let id = SubscriptionId :: generate ( ) ;
1569+ self . send_msg ( ClientMessage :: new_count ( id. clone ( ) , filters) , None )
1570+ . await ?;
1571+
1572+ let mut count = 0 ;
1573+
1574+ let mut notifications = self . notification_sender . subscribe ( ) ;
1575+ time:: timeout ( Some ( timeout) , async {
1576+ while let Ok ( notification) = notifications. recv ( ) . await {
1577+ if let RelayPoolNotification :: Message (
1578+ url,
1579+ RelayMessage :: Count {
1580+ subscription_id,
1581+ count : c,
1582+ } ,
1583+ ) = notification
1584+ {
1585+ if subscription_id == id && url == self . url {
1586+ count = c;
1587+ break ;
1588+ }
1589+ }
1590+ }
1591+ } )
1592+ . await
1593+ . ok_or ( Error :: Timeout ) ?;
1594+
1595+ // Unsubscribe
1596+ self . send_msg ( ClientMessage :: close ( id) , None ) . await ?;
1597+
1598+ Ok ( count)
1599+ }
1600+
15621601 /// Negentropy reconciliation
15631602 pub async fn reconcilie (
15641603 & self ,
You can’t perform that action at this time.
0 commit comments