cancel publish context after 10 seconds.

This commit is contained in:
fiatjaf 2023-05-30 13:43:57 -03:00
parent 01b30b49de
commit bd7b22c4ff
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"os" "os"
@ -123,7 +124,9 @@ standalone:
if relay, err := nostr.RelayConnect(c.Context, url); err != nil { if relay, err := nostr.RelayConnect(c.Context, url); err != nil {
fmt.Fprintf(os.Stderr, "failed to connect: %s\n", err) fmt.Fprintf(os.Stderr, "failed to connect: %s\n", err)
} else { } else {
if status, err := relay.Publish(c.Context, evt); err != nil { ctx, cancel := context.WithTimeout(c.Context, 10*time.Second)
defer cancel()
if status, err := relay.Publish(ctx, evt); err != nil {
fmt.Fprintf(os.Stderr, "failed: %s\n", err) fmt.Fprintf(os.Stderr, "failed: %s\n", err)
} else { } else {
fmt.Fprintf(os.Stderr, "%s.\n", status) fmt.Fprintf(os.Stderr, "%s.\n", status)