[][src]Struct tourniquet::RoundRobin

pub struct RoundRobin<SvcSrc, Svc, E, Conn> where
    Conn: Connector<SvcSrc, Svc, E>, 
{ /* fields omitted */ }

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]

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]

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]

impl<SvcSrc, Svc, E, Conn> Sync for RoundRobin<SvcSrc, Svc, E, Conn> where
    Conn: Sync,
    E: Sync,
    Svc: Send + Sync,
    SvcSrc: Sync
[src]

impl<SvcSrc, Svc, E, Conn> Unpin for RoundRobin<SvcSrc, Svc, E, Conn> where
    Conn: Unpin,
    E: Unpin,
    SvcSrc: Unpin
[src]

impl<SvcSrc, Svc, E, Conn> UnwindSafe for RoundRobin<SvcSrc, Svc, E, Conn> where
    Conn: UnwindSafe,
    E: UnwindSafe,
    Svc: RefUnwindSafe,
    SvcSrc: UnwindSafe
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.