Skip to content

Commit

Permalink
fix goodbye and unsubscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
om26er committed Jul 3, 2024
1 parent b4938c6 commit e771a68
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions messages/goodbye.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ type GoodBye struct {
func NewGoodByeWithFields(fields GoodByeFields) *GoodBye { return &GoodBye{GoodByeFields: fields} }

func NewGoodBye(reason string, details map[string]any) *GoodBye {
if details == nil {
details = map[string]any{}
}

return &GoodBye{GoodByeFields: &goodByeFields{reason: reason, details: details}}
}

Expand Down
8 changes: 6 additions & 2 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (w *Session) SendMessage(msg messages.Message) ([]byte, error) {
unsubscribe.SubscriptionID())
}

w.unsubscribeRequests.Store(unsubscribe.RequestID(), unsubscribe.RequestID())
w.unsubscribeRequests.Store(unsubscribe.RequestID(), unsubscribe.SubscriptionID())

return data, nil
case messages.MessageTypeError:
Expand All @@ -105,6 +105,8 @@ func (w *Session) SendMessage(msg messages.Message) ([]byte, error) {

w.invocationRequests.Delete(errorMsg.RequestID())
return data, nil
case messages.MessageTypeGoodbye:
return data, nil
default:
return nil, fmt.Errorf("send not supported for message of type %T", msg)
}
Expand Down Expand Up @@ -188,7 +190,7 @@ func (w *Session) ReceiveMessage(msg messages.Message) (messages.Message, error)

_, exists = w.subscriptions.LoadAndDelete(subscriptionID)
if !exists {
return nil, fmt.Errorf("received UNSUBSCRIBED for invalid subscriptionID")
return nil, fmt.Errorf("received UNSUBSCRIBED for invalid subscriptionID %d", subscriptionID)
}

return unsubscribed, nil
Expand Down Expand Up @@ -248,6 +250,8 @@ func (w *Session) ReceiveMessage(msg messages.Message) (messages.Message, error)
default:
return nil, fmt.Errorf("unknown error message type %T", msg)
}
case messages.MessageTypeGoodbye:
return msg, nil
default:
return nil, fmt.Errorf("unknown message type %T", msg)
}
Expand Down

0 comments on commit e771a68

Please sign in to comment.