Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
MrSaints committed Nov 24, 2020
1 parent d974afc commit 24bdb8a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ var flightResID string
err := workflow.ExecuteActivity(ctx, activities.BookFlight, name).Get(ctx, &flightResID)
if err != nil {
// If the flight reservation failed, cancel the hotel.
// `saga.Compensate` returns an error, you can check for it and/or log it.
saga.Compensate(ctx)
return err
}
Expand All @@ -66,6 +67,8 @@ if err != nil {

It is worth noting that in simpler examples like above, we do not necessarily need or benefit from the Saga helper this module provides. We can simply call `workflow.ExecuteActivity(..)` within the `if err != nil` block. But, for more complex examples, it can become quite unmanageable, and in such cases, it is often easier to call `saga.Compensate(ctx)`. Your mileage may vary.

The compensation operations are executed in LIFO order.

The various compensation rollback logic can be executed in parallel by setting `ParallelCompensation` to `true`.


Expand Down Expand Up @@ -100,11 +103,17 @@ import "github.com/courtsite/temporal-go-helpers/channel"

sigCh := workflow.GetSignalChannel(ctx, "signal-with-timeout")
var signal SignalStruct
hasTimedOut := channel.ReceiveWithTimeout(ctx, sigCh, &signal, time.Minute * 30)
res := channel.ReceiveWithTimeout(ctx, sigCh, &signal, time.Minute * 30)

if hasTimedOut {
if res.IsCancelled {
// Do something
}

if res.HasTimedOut {
// Do something
}
```

It hides the need to set-up a timer, and selector, reducing cognitive overhead in your workflows.

It also handles context cancellation as well as potential race conditions with the timer future returning at the same time as the signal channel. In the latter scenario, the received signal will be favoured.

0 comments on commit 24bdb8a

Please sign in to comment.