[−][src]Struct tourniquet::RoundRobin
Round Robin manager.
This holds a list of services, a way to connect to said services, and a way to run stuff against this connected service.
Implementations
impl<SvcSrc, Svc, E, Conn> RoundRobin<SvcSrc, Svc, E, Conn> where
SvcSrc: Debug,
E: Next + Display,
Conn: Connector<SvcSrc, Svc, E>,
[src]
SvcSrc: Debug,
E: Next + Display,
Conn: Connector<SvcSrc, Svc, E>,
pub fn new(sources: Vec<SvcSrc>, connector: Conn) -> Self
[src]
Build a new round-robin manager.
The connector is a struct that yields a connected handler to the service, from its service "source" (usually an URL). Note that the connector is lazily executed on demand when a connection is needed.
Example
use std::{io::Error, net::IpAddr}; use tokio::net::TcpStream; use tourniquet::{Connector, RoundRobin}; struct Conn(u16); #[async_trait] impl Connector<IpAddr, Mutex<TcpStream>, Error> for Conn { async fn connect(&self, src: &IpAddr) -> Result<Mutex<TcpStream>, Error> { let Conn(ref port) = self; TcpStream::connect((*src, *port)).await.map(Mutex::new) } } let rr = RoundRobin::new( vec!["185.30.166.38".parse().unwrap(), "66.110.9.37".parse().unwrap()], Conn(6667), );
pub fn set_max_attempts(&mut self, count: usize)
[src]
Set how many times we will try the next service in case of failure.
pub async fn run<R, Fut, T>(&self, run: R) -> Result<T, E> where
R: Fn(Arc<Svc>) -> Fut,
Fut: Future<Output = Result<T, E>>,
[src]
R: Fn(Arc<Svc>) -> Fut,
Fut: Future<Output = Result<T, E>>,
Run the provided async function against an established service connection.
The connection to the service will be established at this point if not already established.
Auto Trait Implementations
impl<SvcSrc, Svc, E, Conn> !RefUnwindSafe for RoundRobin<SvcSrc, Svc, E, Conn>
[src]
impl<SvcSrc, Svc, E, Conn> Send for RoundRobin<SvcSrc, Svc, E, Conn> where
Conn: Send,
E: Send,
Svc: Send + Sync,
SvcSrc: Send,
[src]
Conn: Send,
E: Send,
Svc: Send + Sync,
SvcSrc: Send,
impl<SvcSrc, Svc, E, Conn> Sync for RoundRobin<SvcSrc, Svc, E, Conn> where
Conn: Sync,
E: Sync,
Svc: Send + Sync,
SvcSrc: Sync,
[src]
Conn: Sync,
E: Sync,
Svc: Send + Sync,
SvcSrc: Sync,
impl<SvcSrc, Svc, E, Conn> Unpin for RoundRobin<SvcSrc, Svc, E, Conn> where
Conn: Unpin,
E: Unpin,
SvcSrc: Unpin,
[src]
Conn: Unpin,
E: Unpin,
SvcSrc: Unpin,
impl<SvcSrc, Svc, E, Conn> UnwindSafe for RoundRobin<SvcSrc, Svc, E, Conn> where
Conn: UnwindSafe,
E: UnwindSafe,
Svc: RefUnwindSafe,
SvcSrc: UnwindSafe,
[src]
Conn: UnwindSafe,
E: UnwindSafe,
Svc: RefUnwindSafe,
SvcSrc: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,