fix SubMany() global eosed tracking and SubManyNotifyEOSE() proper notification.

This commit is contained in:
fiatjaf 2025-01-29 21:36:08 -03:00
parent 78a9411d8a
commit 181234d774

View File

@ -263,12 +263,13 @@ func (pool *SimplePool) subMany(
seenAlready := xsync.NewMapOf[string, Timestamp]() seenAlready := xsync.NewMapOf[string, Timestamp]()
ticker := time.NewTicker(seenAlreadyDropTick) ticker := time.NewTicker(seenAlreadyDropTick)
eose := false eosed := false
eoseWg := sync.WaitGroup{} eoseWg := sync.WaitGroup{}
eoseWg.Add(len(urls)) eoseWg.Add(len(urls))
if eoseChan != nil { if eoseChan != nil {
go func() { go func() {
eoseWg.Wait() eoseWg.Wait()
eosed = true
close(eoseChan) close(eoseChan)
}() }()
} }
@ -338,8 +339,7 @@ func (pool *SimplePool) subMany(
<-sub.EndOfStoredEvents <-sub.EndOfStoredEvents
// guard here otherwise a resubscription will trigger a duplicate call to eoseWg.Done() // guard here otherwise a resubscription will trigger a duplicate call to eoseWg.Done()
if !eose { if !eosed {
eose = true
eoseWg.Done() eoseWg.Done()
} }
}() }()
@ -374,7 +374,7 @@ func (pool *SimplePool) subMany(
return return
} }
case <-ticker.C: case <-ticker.C:
if eose { if eosed {
old := Timestamp(time.Now().Add(-seenAlreadyDropTick).Unix()) old := Timestamp(time.Now().Add(-seenAlreadyDropTick).Unix())
for id, value := range seenAlready.Range { for id, value := range seenAlready.Range {
if value < old { if value < old {