Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions go/patterns-use-cases/src/sagas/bookingworkflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package main

import (
"context"
"log"
"slices"

restate "github.com/restatedev/sdk-go"
"github.com/restatedev/sdk-go/server"
"log"
)

type BookingRequest struct {
Expand Down Expand Up @@ -51,7 +53,7 @@ func (BookingWorkflow) Run(ctx restate.Context, req BookingRequest) (err error)
// Run compensations at the end if err != nil
defer func() {
if err != nil {
for _, compensation := range compensations {
for _, compensation := range slices.Backward(compensations) {
if _, compErr := compensation(); compErr != nil {
err = compErr
}
Expand Down
5 changes: 3 additions & 2 deletions go/tutorials/tour-of-orchestration-go/examples/sagas.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package examples

import (
"fmt"
"slices"

"github.com/restatedev/sdk-go"
)
Expand All @@ -14,8 +15,8 @@ func (SubscriptionSaga) Add(ctx restate.Context, req SubscriptionRequest) (err e
// Run compensations at the end if err != nil
defer func() {
if err != nil {
for i := len(compensations) - 1; i >= 0; i-- {
if compErr := compensations[i](); compErr != nil {
for _, compensation := range slices.Backward(compensations) {
if compErr := compensation(); compErr != nil {
err = compErr
}
}
Expand Down
6 changes: 4 additions & 2 deletions go/tutorials/tour-of-workflows-go/examples/sagas.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package examples

import (
"slices"

restate "github.com/restatedev/sdk-go"
)

Expand All @@ -14,8 +16,8 @@ func (SagasWorkflow) Run(ctx restate.WorkflowContext, user User) (res bool, err
// All errors that end up here are terminal errors, so run compensations
// (Retry-able errors got returned by the SDK without ending up here)
if err != nil {
for i := len(compensations) - 1; i >= 0; i-- {
if compErr := compensations[i](); compErr != nil {
for _, compensation := range slices.Backward(compensations) {
if compErr := compensation(); compErr != nil {
err = compErr
}
}
Expand Down
Loading