Update subscription.go

This commit is contained in:
sweep-ai[bot] 2023-07-15 18:59:28 +00:00 committed by GitHub
parent 2f368c783a
commit 41480fddda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,6 +3,7 @@ package nostr
import (
"context"
"fmt"
"log"
"strconv"
"sync"
"sync/atomic"
@ -60,6 +61,14 @@ func (sub *Subscription) GetID() string {
func (sub *Subscription) start() {
var mu sync.Mutex
// Add a defer statement with a recover function to handle panics
defer func() {
if r := recover(); r != nil {
log.Printf("Recovered in start: %s\n", r)
sub.Unsub()
}
}()
for {
select {
case event := <-sub.events: