clear context differentiation on submany/unique.

This commit is contained in:
fiatjaf
2023-10-03 15:43:18 -03:00
parent 7d1091b66b
commit edefc57b28

16
pool.go
View File

@@ -86,18 +86,18 @@ func (pool *SimplePool) subMany(ctx context.Context, urls []string, filters Filt
} }
for evt := range sub.Events { for evt := range sub.Events {
stop := false
if unique { if unique {
_, stop = seenAlready.LoadOrStore(evt.ID, true) if _, seen := seenAlready.LoadOrStore(evt.ID, true); seen {
continue
} }
if !stop { }
select { select {
case events <- IncomingEvent{Event: evt, Relay: relay}: case events <- IncomingEvent{Event: evt, Relay: relay}:
case <-ctx.Done(): case <-ctx.Done():
return return
} }
} }
}
pending.Dec() pending.Dec()
if pending.Value() == 0 { if pending.Value() == 0 {
@@ -160,11 +160,12 @@ func (pool *SimplePool) subManyEose(ctx context.Context, urls []string, filters
return return
} }
stop := false
if unique { if unique {
_, stop = seenAlready.LoadOrStore(evt.ID, true) if _, seen := seenAlready.LoadOrStore(evt.ID, true); seen {
continue
} }
if !stop { }
select { select {
case events <- IncomingEvent{Event: evt, Relay: relay}: case events <- IncomingEvent{Event: evt, Relay: relay}:
case <-ctx.Done(): case <-ctx.Done():
@@ -172,7 +173,6 @@ func (pool *SimplePool) subManyEose(ctx context.Context, urls []string, filters
} }
} }
} }
}
}(NormalizeURL(url)) }(NormalizeURL(url))
} }