Skip to content

Commit

Permalink
Merge pull request #735 from twmb/example-messup
Browse files Browse the repository at this point in the history
eos example: avoid short-circuit logic
  • Loading branch information
twmb authored May 23, 2024
2 parents c77d58e + 0574d20 commit 2bc29e6
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion examples/transactions/eos/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ func inputProducer() {
for i := 0; i < 10; i++ {
cl.Produce(ctx, kgo.StringRecord(msg+strconv.Itoa(i)), e.Promise())
}
commit := kgo.TransactionEndTry(doCommit && e.Err() == nil)
perr := e.Err() // always evaluate e.Err() to ensure we do not short circuit in the logic below (doCommit && ... would fail if doCommit is false!)
commit := kgo.TransactionEndTry(doCommit && perr == nil)

switch err := cl.EndTransaction(ctx, commit); err {
case nil:
Expand Down

0 comments on commit 2bc29e6

Please sign in to comment.