mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-09-27 20:38:41 +02:00
use an atomic counter.
This commit is contained in:
6
relay.go
6
relay.go
@@ -18,7 +18,7 @@ const (
|
|||||||
PublishStatusSucceeded Status = 1
|
PublishStatusSucceeded Status = 1
|
||||||
)
|
)
|
||||||
|
|
||||||
var subscriptionIdCounter = 0
|
var subscriptionIdCounter xsync.Counter
|
||||||
|
|
||||||
func (s Status) String() string {
|
func (s Status) String() string {
|
||||||
switch s {
|
switch s {
|
||||||
@@ -402,8 +402,8 @@ func (r *Relay) QuerySync(ctx context.Context, filter Filter) ([]*Event, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Relay) PrepareSubscription(ctx context.Context) *Subscription {
|
func (r *Relay) PrepareSubscription(ctx context.Context) *Subscription {
|
||||||
current := subscriptionIdCounter
|
current := subscriptionIdCounter.Value()
|
||||||
subscriptionIdCounter++
|
subscriptionIdCounter.Inc()
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
|
|
||||||
|
@@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
type Subscription struct {
|
type Subscription struct {
|
||||||
label string
|
label string
|
||||||
counter int
|
counter int64
|
||||||
conn *Connection
|
conn *Connection
|
||||||
mutex sync.Mutex
|
mutex sync.Mutex
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ func (sub *Subscription) SetLabel(label string) {
|
|||||||
|
|
||||||
// GetID return the Nostr subscription ID as given to the relay, it will be a sequential number, stringified.
|
// GetID return the Nostr subscription ID as given to the relay, it will be a sequential number, stringified.
|
||||||
func (sub *Subscription) GetID() string {
|
func (sub *Subscription) GetID() string {
|
||||||
return sub.label + ":" + strconv.Itoa(sub.counter)
|
return sub.label + ":" + strconv.FormatInt(sub.counter, 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unsub closes the subscription, sending "CLOSE" to relay as in NIP-01.
|
// Unsub closes the subscription, sending "CLOSE" to relay as in NIP-01.
|
||||||
|
Reference in New Issue
Block a user