File tree Expand file tree Collapse file tree 3 files changed +12
-8
lines changed
crates/nostr-relay-pool/src/pool Expand file tree Collapse file tree 3 files changed +12
-8
lines changed Original file line number Diff line number Diff line change 102
102
* pool: add ` AdmitPolicy ` trait ([ Yuki Kishimoto] )
103
103
* pool: add ` ReqExitPolicy::WaitForEvents ` variant ([ Yuki Kishimoto] )
104
104
* pool: add ` RelayPoolBuilder ` ([ Yuki Kishimoto] )
105
+ * pool: add ` RelayPool::is_shutdown ` method ([ Yuki Kishimoto] )
105
106
* ffi: add Mac Catalyst support in Swift package ([ Yuki Kishimoto] )
106
107
* js: add ` KindStandard ` enum ([ Yuki Kishimoto] )
107
108
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ pub(super) type Relays = HashMap<RelayUrl, Relay>;
26
26
pub ( super ) struct AtomicPrivateData {
27
27
pub ( super ) relays : RwLock < Relays > ,
28
28
pub ( super ) subscriptions : RwLock < HashMap < SubscriptionId , Filter > > ,
29
- shutdown : AtomicBool ,
29
+ pub ( super ) shutdown : AtomicBool ,
30
30
}
31
31
32
32
#[ derive( Debug , Clone ) ]
@@ -66,10 +66,6 @@ impl InnerRelayPool {
66
66
}
67
67
}
68
68
69
- pub ( super ) fn is_shutdown ( & self ) -> bool {
70
- self . atomic . shutdown . load ( Ordering :: SeqCst )
71
- }
72
-
73
69
pub async fn shutdown ( & self ) {
74
70
// Mark as shutdown
75
71
// If the previous value was `true`,
Original file line number Diff line number Diff line change 6
6
7
7
use std:: collections:: { HashMap , HashSet } ;
8
8
use std:: future:: Future ;
9
+ use std:: sync:: atomic:: Ordering ;
9
10
use std:: sync:: { Arc , Mutex } ;
10
11
use std:: time:: Duration ;
11
12
@@ -114,6 +115,12 @@ impl RelayPool {
114
115
}
115
116
}
116
117
118
+ /// Check if the relay pool is shutdown.
119
+ #[ inline]
120
+ pub fn is_shutdown ( & self ) -> bool {
121
+ self . inner . atomic . shutdown . load ( Ordering :: SeqCst )
122
+ }
123
+
117
124
/// Completely shutdown pool
118
125
///
119
126
/// This method disconnects and removes all relays from the [`RelayPool`] and then
@@ -257,7 +264,7 @@ impl RelayPool {
257
264
let url: RelayUrl = url. try_into_url ( ) ?;
258
265
259
266
// Check if the pool has been shutdown
260
- if self . inner . is_shutdown ( ) {
267
+ if self . is_shutdown ( ) {
261
268
return Err ( Error :: Shutdown ) ;
262
269
}
263
270
@@ -1296,13 +1303,13 @@ mod tests {
1296
1303
1297
1304
pool. connect ( ) . await ;
1298
1305
1299
- assert ! ( !pool. inner . is_shutdown( ) ) ;
1306
+ assert ! ( !pool. is_shutdown( ) ) ;
1300
1307
1301
1308
tokio:: time:: sleep ( Duration :: from_secs ( 1 ) ) . await ;
1302
1309
1303
1310
pool. shutdown ( ) . await ;
1304
1311
1305
- assert ! ( pool. inner . is_shutdown( ) ) ;
1312
+ assert ! ( pool. is_shutdown( ) ) ;
1306
1313
1307
1314
assert ! ( matches!(
1308
1315
pool. add_relay( & url, RelayOptions :: default ( ) )
You can’t perform that action at this time.
0 commit comments