Skip to content

Commit 0a83da9

Browse files
committed
pool: add RelayPool::is_shutdown method
Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent 8648a64 commit 0a83da9

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
* pool: add `AdmitPolicy` trait ([Yuki Kishimoto])
103103
* pool: add `ReqExitPolicy::WaitForEvents` variant ([Yuki Kishimoto])
104104
* pool: add `RelayPoolBuilder` ([Yuki Kishimoto])
105+
* pool: add `RelayPool::is_shutdown` method ([Yuki Kishimoto])
105106
* ffi: add Mac Catalyst support in Swift package ([Yuki Kishimoto])
106107
* js: add `KindStandard` enum ([Yuki Kishimoto])
107108

crates/nostr-relay-pool/src/pool/inner.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub(super) type Relays = HashMap<RelayUrl, Relay>;
2626
pub(super) struct AtomicPrivateData {
2727
pub(super) relays: RwLock<Relays>,
2828
pub(super) subscriptions: RwLock<HashMap<SubscriptionId, Filter>>,
29-
shutdown: AtomicBool,
29+
pub(super) shutdown: AtomicBool,
3030
}
3131

3232
#[derive(Debug, Clone)]
@@ -66,10 +66,6 @@ impl InnerRelayPool {
6666
}
6767
}
6868

69-
pub(super) fn is_shutdown(&self) -> bool {
70-
self.atomic.shutdown.load(Ordering::SeqCst)
71-
}
72-
7369
pub async fn shutdown(&self) {
7470
// Mark as shutdown
7571
// If the previous value was `true`,

crates/nostr-relay-pool/src/pool/mod.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
77
use std::collections::{HashMap, HashSet};
88
use std::future::Future;
9+
use std::sync::atomic::Ordering;
910
use std::sync::{Arc, Mutex};
1011
use std::time::Duration;
1112

@@ -114,6 +115,12 @@ impl RelayPool {
114115
}
115116
}
116117

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+
117124
/// Completely shutdown pool
118125
///
119126
/// This method disconnects and removes all relays from the [`RelayPool`] and then
@@ -257,7 +264,7 @@ impl RelayPool {
257264
let url: RelayUrl = url.try_into_url()?;
258265

259266
// Check if the pool has been shutdown
260-
if self.inner.is_shutdown() {
267+
if self.is_shutdown() {
261268
return Err(Error::Shutdown);
262269
}
263270

@@ -1296,13 +1303,13 @@ mod tests {
12961303

12971304
pool.connect().await;
12981305

1299-
assert!(!pool.inner.is_shutdown());
1306+
assert!(!pool.is_shutdown());
13001307

13011308
tokio::time::sleep(Duration::from_secs(1)).await;
13021309

13031310
pool.shutdown().await;
13041311

1305-
assert!(pool.inner.is_shutdown());
1312+
assert!(pool.is_shutdown());
13061313

13071314
assert!(matches!(
13081315
pool.add_relay(&url, RelayOptions::default())

0 commit comments

Comments
 (0)