pub struct ForkJoinLayer<A, B> {
pub left: A,
pub right: B,
}Expand description
Fork-join composition layer that tries both left and right concurrently.
Created by the & operator on Policy<L> types:
Policy(A) & Policy(B) produces Policy<ForkJoinLayer<A, B>>.
Both services are called concurrently, and the first successful result is returned. If both fail, an error is returned (currently the left error, but this may change).
This implements the “happy eyeballs” pattern commonly used for IPv4/IPv6 racing, cache racing, or trying multiple backends simultaneously.
§Example
use ninelives::prelude::*;
use std::time::Duration;
use tower_layer::Layer;
// Race two caches - use whichever responds first
let cache_a = Policy(TimeoutLayer::new(Duration::from_millis(100))?);
let cache_b = Policy(TimeoutLayer::new(Duration::from_millis(100))?);
let _policy = cache_a & cache_b;
// Tries both concurrently, returns first Ok result§IPv4/IPv6 Happy Eyeballs Example
use ninelives::prelude::*;
use std::time::Duration;
use tower_layer::Layer;
// Try IPv4 and IPv6 in parallel
let ipv4_path = Policy(TimeoutLayer::new(Duration::from_millis(300))?);
let ipv6_path = Policy(TimeoutLayer::new(Duration::from_millis(300))?);
let _policy = ipv4_path & ipv6_path;Fields§
§left: AThe left strategy (tried concurrently with right)
right: BThe right strategy (tried concurrently with left)
Trait Implementations§
Source§impl<A: Clone, B: Clone> Clone for ForkJoinLayer<A, B>
impl<A: Clone, B: Clone> Clone for ForkJoinLayer<A, B>
Source§fn clone(&self) -> ForkJoinLayer<A, B>
fn clone(&self) -> ForkJoinLayer<A, B>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<S, A, B> Layer<S> for ForkJoinLayer<A, B>
impl<S, A, B> Layer<S> for ForkJoinLayer<A, B>
Auto Trait Implementations§
impl<A, B> Freeze for ForkJoinLayer<A, B>
impl<A, B> RefUnwindSafe for ForkJoinLayer<A, B>where
A: RefUnwindSafe,
B: RefUnwindSafe,
impl<A, B> Send for ForkJoinLayer<A, B>
impl<A, B> Sync for ForkJoinLayer<A, B>
impl<A, B> Unpin for ForkJoinLayer<A, B>
impl<A, B> UnwindSafe for ForkJoinLayer<A, B>where
A: UnwindSafe,
B: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more