Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pubsub): make AckWithResult return success when constructed #8489

Merged
merged 3 commits into from
Aug 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions internal/pubsub/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ func (m *Message) AckWithResult() *AckResult {
if m.ackh != nil {
return m.ackh.OnAckWithResult()
}
return nil
// When the message was constructed directly rather passed in the callback in `sub.Receive`,
// ready the message with success so calling `AckResult.Get` doesn't panic.
return newSuccessAckResult()
}

// NackWithResult declines to acknowledge the message which indicates that
Expand All @@ -206,7 +208,9 @@ func (m *Message) NackWithResult() *AckResult {
if m.ackh != nil {
return m.ackh.OnNackWithResult()
}
return nil
// When the message was constructed directly rather passed in the callback in `sub.Receive`,
// ready the message with success so calling `AckResult.Get` doesn't panic.
return newSuccessAckResult()
}

// NewMessage creates a message with an AckHandler implementation, which should
Expand All @@ -219,3 +223,9 @@ func NewMessage(ackh AckHandler) *Message {
func MessageAckHandler(m *Message) AckHandler {
return m.ackh
}

func newSuccessAckResult() *AckResult {
ar := NewAckResult()
SetAckResult(ar, AcknowledgeStatusSuccess, nil)
return ar
}