pool.QuerySingle()

This commit is contained in:
fiatjaf 2023-08-06 19:57:08 -03:00
parent b522d24c30
commit 5a51f84433
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1

10
pool.go
View File

@ -145,3 +145,13 @@ func (pool *SimplePool) SubManyEose(ctx context.Context, urls []string, filters
return uniqueEvents
}
// QuerySingle returns the first event returned by the first relay, cancels everything else.
func (pool *SimplePool) QuerySingle(ctx context.Context, urls []string, filter Filter) *Event {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
for evt := range pool.SubManyEose(ctx, urls, Filters{filter}) {
return evt
}
return nil
}