Continuum.ActivityRef (continuum v0.5.0)

Copy Markdown View Source

Handle for a successful activity that carries a compensation (saga DSL).

When an activity/2 call is given a compensate: MFA, a successful ({:ok, value}) result is wrapped as {:ok, %Continuum.ActivityRef{}} instead of being returned as a bare term. The ref carries:

  • activity_id — the activity's stable command identity, used to journal and match the compensation for this exact call.
  • result — the unwrapped success value (the value from {:ok, value}).
  • raw_result — the activity's raw return ({:ok, value}).
  • mfa — the activity's {module, function, args}.
  • compensate — the compensation {module, function, args} to run on rollback.

Pass a ref (or {:ok, ref}) to compensate/1. Use Continuum.unwrap/1 to recover the raw activity return when you don't need the compensation handle.

Activities without a compensate: option are unchanged: they return a bare term, exactly as in v0.2.

Summary

Types

t()

@type t() :: %Continuum.ActivityRef{
  activity_id: term(),
  compensate: {module(), atom(), list()},
  mfa: {module(), atom(), list()},
  raw_result: term(),
  result: term()
}