mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-09-18 19:41:44 +02:00
close SubMany channel when all underlying subscriptions die.
This commit is contained in:
8
pool.go
8
pool.go
@@ -60,6 +60,9 @@ func (pool *SimplePool) SubMany(
|
||||
uniqueEvents := make(chan *Event)
|
||||
seenAlready := xsync.NewMapOf[bool]()
|
||||
|
||||
pending := xsync.Counter{}
|
||||
initial := len(urls)
|
||||
pending.Add(int64(initial))
|
||||
for _, url := range urls {
|
||||
go func(nm string) {
|
||||
relay, err := pool.EnsureRelay(nm)
|
||||
@@ -78,6 +81,11 @@ func (pool *SimplePool) SubMany(
|
||||
uniqueEvents <- evt
|
||||
}
|
||||
}
|
||||
|
||||
pending.Dec()
|
||||
if pending.Value() == 0 {
|
||||
close(uniqueEvents)
|
||||
}
|
||||
}(NormalizeURL(url))
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user