Skip to content

Commit

Permalink
fix(pubsub): make AckWithResult return success when constructed (goog…
Browse files Browse the repository at this point in the history
  • Loading branch information
hongalex authored Aug 28, 2023
1 parent d440d75 commit 38a040e
Showing 1 changed file with 12 additions and 2 deletions.
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
}

0 comments on commit 38a040e

Please sign in to comment.