Chronicle.Events.ConcurrencyScope (cratis_chronicle v1.0.3)

Copy Markdown View Source

Represents a concurrency scope for Chronicle append operations.

Concurrency scopes let you assert the expected tail sequence number before appending one or more events. You can optionally narrow the check to the current event source, stream, source type, and event types.

alias Chronicle.Events.ConcurrencyScope

scope =
  ConcurrencyScope.for_event_source(3,
    event_types: [MyApp.Events.FundsDeposited, MyApp.Events.FundsWithdrawn]
  )

:ok = Chronicle.append_many("account-42", [...], concurrency_scope: scope)

The event_source_id option is a boolean because the actual event source id comes from the Chronicle.append/3 or Chronicle.append_many/3 call.

Summary

Functions

Creates a concurrency scope that includes the current append event source id.

Creates a new concurrency scope.

Returns the sentinel scope representing no explicit concurrency constraint.

Types

event_type_module()

@type event_type_module() :: module()

option()

@type option() ::
  {:event_source_id, boolean()}
  | {:event_stream_type, String.t() | atom() | nil}
  | {:event_stream_id, String.t() | atom() | nil}
  | {:event_source_type, String.t() | atom() | nil}
  | {:event_types, [event_type_module()] | nil}

t()

@type t() :: %Chronicle.Events.ConcurrencyScope{
  event_source_id: boolean(),
  event_source_type: String.t(),
  event_stream_id: String.t(),
  event_stream_type: String.t(),
  event_types: [event_type_module()],
  sequence_number: non_neg_integer()
}

Functions

for_event_source(sequence_number, opts \\ [])

@spec for_event_source(non_neg_integer(), [option()]) :: t()

Creates a concurrency scope that includes the current append event source id.

new(sequence_number, opts \\ [])

@spec new(non_neg_integer(), [option()]) :: t()

Creates a new concurrency scope.

none()

@spec none() :: t()

Returns the sentinel scope representing no explicit concurrency constraint.