Struct tourniquet::RoundRobin[][src]

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

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

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),
);

Set how many times we will try the next service in case of failure.

Set how many times we will try the next service in case of failure.

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

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more