QuerySync() relay method.

This commit is contained in:
fiatjaf 2022-11-26 19:32:03 -03:00
parent e8bc11e4f9
commit 0c39530d57
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1

View File

@ -222,6 +222,21 @@ func (r *Relay) Subscribe(filters Filters) *Subscription {
return sub
}
func (r *Relay) QuerySync(filter Filter, timeout time.Duration) []Event {
sub := r.Subscribe(Filters{filter})
var events []Event
for {
select {
case evt := <-sub.Events:
events = append(events, evt)
case <-sub.EndOfStoredEvents:
return events
case <-time.After(timeout):
return events
}
}
}
func (r *Relay) PrepareSubscription() *Subscription {
random := make([]byte, 7)
rand.Read(random)