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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
subscription.Events <- EventMessage{
|
if !subscription.stopped {
|
||||||
Relay: nm,
|
subscription.Events <- EventMessage{
|
||||||
Event: event,
|
Relay: nm,
|
||||||
|
Event: event,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,6 +9,8 @@ type Subscription struct {
|
|||||||
|
|
||||||
started bool
|
started bool
|
||||||
UniqueEvents chan Event
|
UniqueEvents chan Event
|
||||||
|
|
||||||
|
stopped bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type EventMessage struct {
|
type EventMessage struct {
|
||||||
@@ -24,6 +26,7 @@ func (subscription Subscription) Unsub() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
subscription.stopped = true
|
||||||
if subscription.Events != nil {
|
if subscription.Events != nil {
|
||||||
close(subscription.Events)
|
close(subscription.Events)
|
||||||
}
|
}
|
||||||
@@ -57,7 +60,9 @@ func (subscription Subscription) startHandlingUnique() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
seen[em.Event.ID] = struct{}{}
|
seen[em.Event.ID] = struct{}{}
|
||||||
subscription.UniqueEvents <- em.Event
|
if !subscription.stopped {
|
||||||
|
subscription.UniqueEvents <- em.Event
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user