diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-11 12:50:05 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-11 12:50:05 +0000 |
| commit | 82c5783a4d40c4273cb12317ec9bf88a2e281a04 (patch) | |
| tree | 508623c92193573c98c0c476b18c36ca77207316 /docs/tutorials/getting-started.md | |
| parent | 83844a528365e657cd5f4d2cda51d72ced9900da (diff) | |
refactor: use Relay::notifications() for event-driven disconnect detection
Replace the 1-second polling loop with nostr-sdk's relay-level notification
system that provides immediate disconnect detection via RelayNotification::RelayStatus.
Key changes:
- Use relay.notifications() instead of client.notifications()
- Handle RelayNotification::RelayStatus { Disconnected | Terminated } to detect
connection loss immediately without polling
- Remove tokio::select! with interval timer - now uses simple match loop
- Handle additional notification types (Authenticated, AuthenticationFailed)
Why this is better:
- Event-driven vs polling: no wasted CPU cycles checking every second
- Immediate detection: disconnect triggers notification instantly
- Uses nostr-sdk's built-in mechanism that was previously inaccessible at pool level
(RelayStatus notifications are filtered out in RelayPoolNotification)
Technical note: RelayNotification::RelayStatus is only available via
Relay::notifications(), not Client::notifications(), because the pool-level
broadcast filters out status change events.
Future refactoring opportunity: Consider restructuring RelayConnection to hold
a Relay directly instead of wrapping a Client, since we only manage one relay
per connection anyway.
Diffstat (limited to 'docs/tutorials/getting-started.md')
0 files changed, 0 insertions, 0 deletions