disentangle things a little more.

having a single loop for everything was too much. goroutines things were getting stuck.
This commit is contained in:
fiatjaf
2023-06-23 16:22:57 -03:00
parent f0a35d7ab2
commit ac0c0769fe
2 changed files with 107 additions and 96 deletions

View File

@@ -57,20 +57,25 @@ func (sub *Subscription) GetID() string {
// Unsub closes the subscription, sending "CLOSE" to relay as in NIP-01.
// Unsub() also closes the channel sub.Events and makes a new one.
func (sub *Subscription) Unsub() {
id := sub.GetID()
go sub.Close()
sub.live = false
id := sub.GetID()
sub.Relay.Subscriptions.Delete(id)
// do this so we don't have the possibility of closing the Events channel and then trying to send to it
sub.Relay.subscriptionChannelCloseQueue <- sub
}
// Close just sends a CLOSE message. You probably want Unsub() instead.
func (sub *Subscription) Close() {
if sub.Relay.IsConnected() {
id := sub.GetID()
closeMsg := CloseEnvelope(id)
closeb, _ := (&closeMsg).MarshalJSON()
debugLog("{%s} sending %v", sub.Relay.URL, closeb)
sub.Relay.Write(closeb)
}
sub.live = false
sub.Relay.Subscriptions.Delete(id)
// do this so we don't have the possibility of closing the Events channel and then trying to send to it
sub.Relay.subscriptionChannelCloseQueue <- sub
}
// Sub sets sub.Filters and then calls sub.Fire(ctx).