Buffers event appends and commits them as a single Chronicle append-many operation.
Use begin/1 to create a unit of work and make it current for the calling
process. Calls to Chronicle.append/3, Chronicle.append_many/3, or a
transactional event sequence are buffered until commit/1 is called.
Summary
Functions
Adds an event to the unit of work.
Begins a new unit of work and makes it current for the calling process.
Returns a specification to start this module under a supervisor.
Commits the buffered events.
Returns the correlation id for a unit of work.
Returns the current unit of work for the calling process.
Returns the buffered events in insertion order.
Returns whether the calling process currently has an active unit of work.
Returns whether the unit of work has been committed or rolled back.
Returns whether the unit of work completed successfully.
Returns the last committed sequence number if available.
Registers a callback that runs when the unit of work is committed or rolled back.
Rolls back the unit of work and clears the buffered events.
Sets an existing unit of work as current for the calling process.
Tries to get a unit of work by correlation id.
Runs a function inside a unit of work and commits it if the function succeeds. Rolls the unit of work back if the function raises.
Types
Functions
@spec add_event( t(), String.t(), Chronicle.EventSequences.EventForEventSourceId.t(), keyword() ) :: :ok
Adds an event to the unit of work.
Begins a new unit of work and makes it current for the calling process.
Returns a specification to start this module under a supervisor.
See Supervisor.
Commits the buffered events.
@spec correlation_id(t()) :: Chronicle.Correlation.CorrelationId.t()
Returns the correlation id for a unit of work.
@spec current() :: t()
Returns the current unit of work for the calling process.
@spec get_events(t()) :: [Chronicle.EventSequences.EventForEventSourceId.t()]
Returns the buffered events in insertion order.
@spec has_current?() :: boolean()
Returns whether the calling process currently has an active unit of work.
Returns whether the unit of work has been committed or rolled back.
Returns whether the unit of work completed successfully.
@spec last_committed_sequence_number(t()) :: non_neg_integer() | nil
Returns the last committed sequence number if available.
@spec on_completed(t(), on_completed()) :: :ok
Registers a callback that runs when the unit of work is committed or rolled back.
@spec rollback(t()) :: :ok
Rolls back the unit of work and clears the buffered events.
Sets an existing unit of work as current for the calling process.
@spec try_get_for(Chronicle.Correlation.CorrelationId.t() | String.t()) :: {:ok, t()} | :error
Tries to get a unit of work by correlation id.
Runs a function inside a unit of work and commits it if the function succeeds. Rolls the unit of work back if the function raises.