added sub.mutex handling in the relay Connect() function (#37)

This commit is contained in:
barkyq
2023-01-15 07:19:00 -05:00
committed by GitHub
parent 635c1b0132
commit a37ffacc74
3 changed files with 25 additions and 8 deletions

View File

@@ -43,7 +43,8 @@ if _, v, err := nip19.Decode(npub); err == nil {
panic(err)
}
sub := relay.Subscribe(context.Background(), filters)
ctx, cancel := context.WithCancel(context.Background())
sub := relay.Subscribe(ctx, filters)
go func() {
<-sub.EndOfStoredEvents
@@ -52,7 +53,9 @@ go func() {
for ev := range sub.Events {
// handle returned event.
// channel will stay open until sub.Unsub() is called
// channel will stay open until the ctx is cancelled (in this case, by calling cancel())
fmt.Println(ev.ID)
}
```