Skip to content

Commit 8648a64

Browse files
committed
pool: refactor RelayPool::shutdown logic to use atomic swap
Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent dbcb8d7 commit 8648a64

File tree

1 file changed

+4
-5
lines changed
  • crates/nostr-relay-pool/src/pool

1 file changed

+4
-5
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ impl InnerRelayPool {
7171
}
7272

7373
pub async fn shutdown(&self) {
74-
// TODO: use atomic swap?
75-
if self.is_shutdown() {
74+
// Mark as shutdown
75+
// If the previous value was `true`,
76+
// meaning that was already shutdown, immediately returns.
77+
if self.atomic.shutdown.swap(true, Ordering::SeqCst) {
7678
return;
7779
}
7880

@@ -83,9 +85,6 @@ impl InnerRelayPool {
8385
let _ = self
8486
.notification_sender
8587
.send(RelayPoolNotification::Shutdown);
86-
87-
// Mark as shutdown
88-
self.atomic.shutdown.store(true, Ordering::SeqCst);
8988
}
9089

9190
pub async fn force_remove_all_relays(&self) {

0 commit comments

Comments
 (0)