mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-03-17 21:32:56 +01:00
SimplePool.PublishMany(), finally.
This commit is contained in:
parent
4cf3cdbe66
commit
28b05cdd9b
26
pool.go
26
pool.go
@ -178,6 +178,32 @@ func (pool *SimplePool) EnsureRelay(url string) (*Relay, error) {
|
||||
return relay, nil
|
||||
}
|
||||
|
||||
type PublishResult struct {
|
||||
Error error
|
||||
RelayURL string
|
||||
Relay *Relay
|
||||
}
|
||||
|
||||
func (pool *SimplePool) PublishMany(ctx context.Context, urls []string, evt Event) chan PublishResult {
|
||||
ch := make(chan PublishResult, len(urls))
|
||||
|
||||
go func() {
|
||||
for _, url := range urls {
|
||||
relay, err := pool.EnsureRelay(url)
|
||||
if err != nil {
|
||||
ch <- PublishResult{err, url, nil}
|
||||
} else {
|
||||
err = relay.Publish(ctx, evt)
|
||||
ch <- PublishResult{err, url, relay}
|
||||
}
|
||||
}
|
||||
|
||||
close(ch)
|
||||
}()
|
||||
|
||||
return ch
|
||||
}
|
||||
|
||||
// SubMany opens a subscription with the given filters to multiple relays
|
||||
// the subscriptions only end when the context is canceled
|
||||
func (pool *SimplePool) SubMany(
|
||||
|
Loading…
x
Reference in New Issue
Block a user