From 5a51f8443343c180792f869e66d14aed2be15cde Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Sun, 6 Aug 2023 19:57:08 -0300 Subject: [PATCH] pool.QuerySingle() --- pool.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pool.go b/pool.go index 978bc34..9949804 100644 --- a/pool.go +++ b/pool.go @@ -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 +}