mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-12-19 20:25:04 +01:00
oops: stop replacing connectionContext with Connect(ctx).
This commit is contained in:
8
relay.go
8
relay.go
@@ -84,12 +84,13 @@ func (r *Relay) Context() context.Context { return r.connectionContext }
|
|||||||
// pass a custom context to the underlying relay connection, use NewRelay() and
|
// pass a custom context to the underlying relay connection, use NewRelay() and
|
||||||
// then Relay.Connect().
|
// then Relay.Connect().
|
||||||
func (r *Relay) Connect(ctx context.Context) error {
|
func (r *Relay) Connect(ctx context.Context) error {
|
||||||
connectionContext, cancel := context.WithCancel(ctx)
|
if r.connectionContext == nil {
|
||||||
|
connectionContext, cancel := context.WithCancel(context.Background())
|
||||||
r.connectionContext = connectionContext
|
r.connectionContext = connectionContext
|
||||||
r.connectionContextCancel = cancel
|
r.connectionContextCancel = cancel
|
||||||
|
}
|
||||||
|
|
||||||
if r.URL == "" {
|
if r.URL == "" {
|
||||||
cancel()
|
|
||||||
return fmt.Errorf("invalid relay URL '%s'", r.URL)
|
return fmt.Errorf("invalid relay URL '%s'", r.URL)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,7 +103,6 @@ func (r *Relay) Connect(ctx context.Context) error {
|
|||||||
|
|
||||||
conn, err := NewConnection(ctx, r.URL, r.RequestHeader)
|
conn, err := NewConnection(ctx, r.URL, r.RequestHeader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cancel()
|
|
||||||
return fmt.Errorf("error opening websocket to '%s': %w", r.URL, err)
|
return fmt.Errorf("error opening websocket to '%s': %w", r.URL, err)
|
||||||
}
|
}
|
||||||
r.Connection = conn
|
r.Connection = conn
|
||||||
@@ -123,7 +123,6 @@ func (r *Relay) Connect(ctx context.Context) error {
|
|||||||
go func() {
|
go func() {
|
||||||
ticker := time.NewTicker(29 * time.Second)
|
ticker := time.NewTicker(29 * time.Second)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
defer cancel()
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
@@ -138,7 +137,6 @@ func (r *Relay) Connect(ctx context.Context) error {
|
|||||||
|
|
||||||
// handling received messages
|
// handling received messages
|
||||||
go func() {
|
go func() {
|
||||||
defer cancel()
|
|
||||||
for {
|
for {
|
||||||
message, err := conn.ReadMessage(r.connectionContext)
|
message, err := conn.ReadMessage(r.connectionContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user