Skip to main content

execute

Function execute 

Source
pub async fn execute<C, S>(
    store: S,
    command: C,
    policy: RetryPolicy,
) -> Result<ExecutionResponse, CommandError>
where C: CommandLogic, S: EventStore,
Expand description

Execute a command against the event store with a custom retry policy.

This is the primary entry point for EventCore. It orchestrates the complete command execution workflow: loading state from multiple streams, validating business rules, and atomically committing resulting events.

Internally, this function drives an ExecutePipeline state machine that yields effects (read stream, append events, sleep). This function is the thin shell loop that dispatches those effects to the EventStore trait.

§Type Parameters

  • C - A command implementing CommandLogic that defines the business operation
  • S - An event store implementing EventStore for persistence

§Parameters

  • store - The event store for reading/writing events
  • command - The command to execute
  • policy - Retry policy configuration (max attempts, backoff strategy, etc.)

§Errors

Returns CommandError if:

  • Stream resolution fails
  • Event loading fails
  • Business rule validation fails (via command’s handle())
  • Event persistence fails
  • Optimistic concurrency conflicts occur after exhausting retries