pub struct Effect<A, E, S> { /* private fields */ }Expand description
A description of a program. A is the success value, E is the expected
error, and S is the service environment required to run it.
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.
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.
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 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.