mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-09-19 12:01:55 +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)
|
uniqueEvents := make(chan *Event)
|
||||||
seenAlready := xsync.NewMapOf[bool]()
|
seenAlready := xsync.NewMapOf[bool]()
|
||||||
|
|
||||||
|
pending := xsync.Counter{}
|
||||||
|
initial := len(urls)
|
||||||
|
pending.Add(int64(initial))
|
||||||
for _, url := range urls {
|
for _, url := range urls {
|
||||||
go func(nm string) {
|
go func(nm string) {
|
||||||
relay, err := pool.EnsureRelay(nm)
|
relay, err := pool.EnsureRelay(nm)
|
||||||
@@ -78,6 +81,11 @@ func (pool *SimplePool) SubMany(
|
|||||||
uniqueEvents <- evt
|
uniqueEvents <- evt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pending.Dec()
|
||||||
|
if pending.Value() == 0 {
|
||||||
|
close(uniqueEvents)
|
||||||
|
}
|
||||||
}(NormalizeURL(url))
|
}(NormalizeURL(url))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user