Enum Effect
Sourcepub enum Effect<T> {
Ok(T),
Err(ErrorEffect),
Retry {
after: Duration,
attempt: u32,
max_attempts: u32,
reason: String,
},
Compensate {
action: CompensationAction,
cause: Box<ErrorEffect>,
},
Pending {
waiting_for: WaitCondition,
resume_token: EventId,
progress_hint: Option<Value>,
},
Batch(Vec<Effect<T>>),
}Expand description
An effect represents the outcome of an operation.
Effects are more expressive than simple Result<T, E> because they can
represent retry conditions, compensation actions, and pending states.
§Variants
Ok(T): Successful resultErr(ErrorEffect): Domain-level error (replayable, affects downstream)Retry: Operation should be retriedCompensate: Compensation action is neededPending: Operation is waiting for somethingBatch: Multiple effects (for fan-out scenarios)
Variants§
Ok(T)
Successful result
Err(ErrorEffect)
Domain-level error (must be persisted and handled)
Retry
Operation should be retried
Fields
Compensate
Compensation action is needed
Fields
action: CompensationActionThe action to take
cause: Box<ErrorEffect>The error that caused compensation
Pending
Operation is waiting for something
Fields
waiting_for: WaitConditionWhat the operation is waiting for
Batch(Vec<Effect<T>>)
Multiple effects (for fan-out scenarios)
Implementations§
Source§impl<T> Effect<T>
impl<T> Effect<T>
Sourcepub fn err(error: ErrorEffect) -> Effect<T>
pub fn err(error: ErrorEffect) -> Effect<T>
Create an error effect.
Sourcepub fn domain_error(
error: DomainError,
source_event: EventId,
position: DagPosition,
) -> Effect<T>
pub fn domain_error( error: DomainError, source_event: EventId, position: DagPosition, ) -> Effect<T>
Create a domain error effect.
Sourcepub fn retry(
after: Duration,
attempt: u32,
max_attempts: u32,
reason: impl Into<String>,
) -> Effect<T>
pub fn retry( after: Duration, attempt: u32, max_attempts: u32, reason: impl Into<String>, ) -> Effect<T>
Create a retry effect.
Sourcepub fn pending(waiting_for: WaitCondition, resume_token: EventId) -> Effect<T>
pub fn pending(waiting_for: WaitCondition, resume_token: EventId) -> Effect<T>
Create a pending effect.
Sourcepub fn needs_retry(&self) -> bool
pub fn needs_retry(&self) -> bool
Check if this effect requires retry.
Sourcepub fn is_pending(&self) -> bool
pub fn is_pending(&self) -> bool
Check if this effect is pending.
Sourcepub fn into_result(self) -> Result<T, ErrorEffect>
pub fn into_result(self) -> Result<T, ErrorEffect>
Convert to a Result, losing retry/compensation information.
Sourcepub fn expect(self, msg: &str) -> T
pub fn expect(self, msg: &str) -> T
Extract the success value, panicking with a custom message if not Ok.
Sourcepub fn and_then<U, F>(self, f: F) -> Effect<U>
pub fn and_then<U, F>(self, f: F) -> Effect<U>
Chain a function that returns an Effect on the success value.
If self is Ok(t), returns f(t). Otherwise, returns the original
non-Ok effect unchanged.
Sourcepub fn map_err<F>(self, f: F) -> Effect<T>
pub fn map_err<F>(self, f: F) -> Effect<T>
Map the error effect using a transformation function.
Recurses into Batch to transform errors within each inner effect.
Sourcepub fn or_else<F>(self, f: F) -> Effect<T>
pub fn or_else<F>(self, f: F) -> Effect<T>
Handle an error by applying a recovery function.
Recurses into Batch to recover errors within each inner effect.
Sourcepub fn unwrap_or(self, default: T) -> T
pub fn unwrap_or(self, default: T) -> T
Extract the success value or return a default.
If self is Ok(t), returns t. Otherwise, returns default.
Sourcepub fn unwrap_or_else<F>(self, f: F) -> Twhere
F: FnOnce(ErrorEffect) -> T,
pub fn unwrap_or_else<F>(self, f: F) -> Twhere
F: FnOnce(ErrorEffect) -> T,
Extract the success value or compute a default from the error.
If self is Ok(t), returns t. Otherwise, returns f(e) where
e is the error effect (or a synthesized one for non-error variants).