pub struct Effect<A, E, S> { /* private fields */ }Implementations§
Source§impl<A, E, S> Effect<A, E, S>
impl<A, E, S> Effect<A, E, S>
pub fn succeed(value: A) -> Selfwhere
A: Clone,
pub fn fail(error: E) -> Selfwhere
E: Clone,
pub fn die(message: impl Into<String>) -> Self
Sourcepub fn from_async<F, Fut>(f: F) -> Self
pub fn from_async<F, Fut>(f: F) -> Self
Build a program from services and a cancellation token. The function
runs only when Effect::run is called.
Sourcepub fn from_async_observed<F, Fut>(f: F) -> Self
pub fn from_async_observed<F, Fut>(f: F) -> Self
Like Self::from_async, but f still runs when the token is already
cancelled. f has to observe the token. A caller that must append a
fact on cancel uses this. Self::from_async returns
Exit::Interrupt before f starts, and dropping that future would
skip the fact.
pub fn map<B, F>(&self, f: F) -> Effect<B, E, S>
pub fn and_then<B, F>(&self, f: F) -> Effect<B, E, S>
Sourcepub fn catch_fail<F>(&self, f: F) -> Self
pub fn catch_fail<F>(&self, f: F) -> Self
Handle an expected failure. Defects and interruption pass through.
Sourcepub fn retry(&self, schedule: Schedule) -> Selfwhere
E: Clone,
pub fn retry(&self, schedule: Schedule) -> Selfwhere
E: Clone,
Retry expected failures. Interruption and defects are not retried.
The wrapped effect owns cancellation: an observed effect still runs
when the token is already cancelled so it can append its interrupt
facts, and an effect built with Self::from_async refuses before
its body starts. Only the backoff sleep between attempts is cut
short by the token.
pub fn timeout(&self, duration: Duration) -> Self
pub fn with_span(&self, name: impl Into<String>) -> Self
Sourcepub fn zip_par<B>(&self, right: &Effect<B, E, S>) -> Effect<(A, B), E, S>
pub fn zip_par<B>(&self, right: &Effect<B, E, S>) -> Effect<(A, B), E, S>
Run left and right together. The first expected failure or defect
cancels the sibling and waits for that sibling to finish.
Sourcepub fn race(&self, other: &Self) -> Self
pub fn race(&self, other: &Self) -> Self
First success or failure wins. The other side is cancelled and awaited.
Sourcepub fn bracket<B, F, R>(&self, release: R, body: F) -> Effect<B, E, S>
pub fn bracket<B, F, R>(&self, release: R, body: F) -> Effect<B, E, S>
Acquire a resource, use it, and release it on success, expected failure, and cancellation. Dropping the running future releases it too.
Sourcepub fn map_services<S2>(
self,
map: impl Fn(Arc<S2>) -> Arc<S> + Send + Sync + 'static,
) -> Effect<A, E, S2>
pub fn map_services<S2>( self, map: impl Fn(Arc<S2>) -> Arc<S> + Send + Sync + 'static, ) -> Effect<A, E, S2>
Map the caller’s services while preserving cancellation and the trace.
Sourcepub fn provide<S2>(self, services: S) -> Effect<A, E, S2>
pub fn provide<S2>(self, services: S) -> Effect<A, E, S2>
Replace the service environment. The resulting program no longer
requires S; the caller supplies a different environment at the edge.
pub async fn run( self, services: Arc<S>, ) -> (Result<A, Exit<E>>, Vec<TraceEvent>)
Sourcepub async fn run_with_cancel(
self,
services: Arc<S>,
cancel: CancellationToken,
) -> (Result<A, Exit<E>>, Vec<TraceEvent>)
pub async fn run_with_cancel( self, services: Arc<S>, cancel: CancellationToken, ) -> (Result<A, Exit<E>>, Vec<TraceEvent>)
Run with the caller’s token. Self::run passes a fresh token that
nothing else cancels.