mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-03-17 21:32:56 +01:00
error instead of panic'ing when opening subscription.
This commit is contained in:
parent
a35cdff6c8
commit
a7303c385b
8
relay.go
8
relay.go
@ -377,6 +377,10 @@ func (r *Relay) publish(ctx context.Context, id string, env Envelope) error {
|
||||
func (r *Relay) Subscribe(ctx context.Context, filters Filters, opts ...SubscriptionOption) (*Subscription, error) {
|
||||
sub := r.PrepareSubscription(ctx, filters, opts...)
|
||||
|
||||
if r.Connection == nil {
|
||||
return nil, fmt.Errorf("not connected to %s", r.URL)
|
||||
}
|
||||
|
||||
if err := sub.Fire(); err != nil {
|
||||
return nil, fmt.Errorf("couldn't subscribe to %v at %s: %w", filters, r.URL, err)
|
||||
}
|
||||
@ -389,10 +393,6 @@ func (r *Relay) Subscribe(ctx context.Context, filters Filters, opts ...Subscrip
|
||||
// Remember to cancel subscriptions, either by calling `.Unsub()` on them or ensuring their `context.Context` will be canceled at some point.
|
||||
// Failure to do that will result in a huge number of halted goroutines being created.
|
||||
func (r *Relay) PrepareSubscription(ctx context.Context, filters Filters, opts ...SubscriptionOption) *Subscription {
|
||||
if r.Connection == nil {
|
||||
panic(fmt.Errorf("must call .Connect() first before calling .Subscribe()"))
|
||||
}
|
||||
|
||||
current := subscriptionIDCounter.Add(1)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user