Skip to content

Commit

Permalink
adding thorclient.Subscription.Unsubscribe errors
Browse files Browse the repository at this point in the history
  • Loading branch information
otherview committed Dec 20, 2024
1 parent 3558bd5 commit 00b0597
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion thorclient/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ type EventWrapper[T any] struct {
// Subscription is used to handle the active subscription
type Subscription[T any] struct {
EventChan <-chan EventWrapper[T]
Unsubscribe func()
Unsubscribe func() error
}
13 changes: 10 additions & 3 deletions thorclient/wsclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,17 @@ func subscribe[T any](conn *websocket.Conn) *common.Subscription[*T] {

return &common.Subscription[*T]{
EventChan: eventChan,
Unsubscribe: func() {
Unsubscribe: func() error {
closed = true
conn.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""))
conn.Close()
err := conn.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""))
if err != nil {
return fmt.Errorf("failed to issue close message: %w", err)
}
err = conn.Close()
if err != nil {
return fmt.Errorf("failed to close connections: %w", err)
}
return nil
},
}
}
Expand Down

0 comments on commit 00b0597

Please sign in to comment.