mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-09-18 11:32:25 +02:00
avoid sending to closed Events/UniqueEvents channels.
This commit is contained in:
@@ -152,9 +152,11 @@ func (r *RelayPool) Add(url string, policy RelayPoolPolicy) error {
|
||||
continue
|
||||
}
|
||||
|
||||
subscription.Events <- EventMessage{
|
||||
Relay: nm,
|
||||
Event: event,
|
||||
if !subscription.stopped {
|
||||
subscription.Events <- EventMessage{
|
||||
Relay: nm,
|
||||
Event: event,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -9,6 +9,8 @@ type Subscription struct {
|
||||
|
||||
started bool
|
||||
UniqueEvents chan Event
|
||||
|
||||
stopped bool
|
||||
}
|
||||
|
||||
type EventMessage struct {
|
||||
@@ -24,6 +26,7 @@ func (subscription Subscription) Unsub() {
|
||||
})
|
||||
}
|
||||
|
||||
subscription.stopped = true
|
||||
if subscription.Events != nil {
|
||||
close(subscription.Events)
|
||||
}
|
||||
@@ -57,7 +60,9 @@ func (subscription Subscription) startHandlingUnique() {
|
||||
continue
|
||||
}
|
||||
seen[em.Event.ID] = struct{}{}
|
||||
subscription.UniqueEvents <- em.Event
|
||||
if !subscription.stopped {
|
||||
subscription.UniqueEvents <- em.Event
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user