mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-10-09 20:33:27 +02:00
added sub.mutex handling in the relay Connect() function (#37)
This commit is contained in:
@@ -24,6 +24,8 @@ type EventMessage struct {
|
||||
Relay string
|
||||
}
|
||||
|
||||
// Unsub closes the subscription, sending "CLOSE" to relay as in NIP-01
|
||||
// Unsub() also closes the channel sub.Events
|
||||
func (sub *Subscription) Unsub() {
|
||||
sub.mutex.Lock()
|
||||
defer sub.mutex.Unlock()
|
||||
@@ -35,11 +37,14 @@ func (sub *Subscription) Unsub() {
|
||||
sub.stopped = true
|
||||
}
|
||||
|
||||
// Sub sets sub.Filters and then calls sub.Fire(ctx)
|
||||
func (sub *Subscription) Sub(ctx context.Context, filters Filters) {
|
||||
sub.Filters = filters
|
||||
sub.Fire(ctx)
|
||||
}
|
||||
|
||||
// Fire sends the "REQ" command to the relay
|
||||
// when ctx is cancelled, sub.Unsub() is called, closing the subscription
|
||||
func (sub *Subscription) Fire(ctx context.Context) {
|
||||
message := []interface{}{"REQ", sub.id}
|
||||
for _, filter := range sub.Filters {
|
||||
|
Reference in New Issue
Block a user