pub struct AsyncLoadBalancer<I: Send + Clone + 'static, O: Send + Clone + 'static> {
pub output_rx: Receiver<O>,
pub input_tx: Sender<I>,
pub handles: Vec<JoinHandle<()>>,
}Expand description
An asynchronous load balancer for distributing tasks across multiple workers, using tokio! Please remember that outputs might not be 1/1 timewise with inputs. Inputs ordered A,B,C could come out ordered A,C,B!
§Example:
let mut lb: LoadBalancer<i32, i32> = LoadBalancer::new(100, 4, |x| {Box::pin(async move {x * 2})});
for i in 0..100 {
lb.input_tx.send(i).await.unwrap();
}
for i in 0..100 {
let result = lb.recv().await.unwrap();
assert_eq!(result % 2, 0);
println!("Received: {}", result);
}Fields§
§output_rx: Receiver<O>§input_tx: Sender<I>§handles: Vec<JoinHandle<()>>Implementations§
Source§impl<I, O> AsyncLoadBalancer<I, O>
impl<I, O> AsyncLoadBalancer<I, O>
Trait Implementations§
Source§impl<I, O> Drop for AsyncLoadBalancer<I, O>
impl<I, O> Drop for AsyncLoadBalancer<I, O>
Auto Trait Implementations§
impl<I, O> Freeze for AsyncLoadBalancer<I, O>
impl<I, O> RefUnwindSafe for AsyncLoadBalancer<I, O>
impl<I, O> Send for AsyncLoadBalancer<I, O>
impl<I, O> Sync for AsyncLoadBalancer<I, O>
impl<I, O> Unpin for AsyncLoadBalancer<I, O>
impl<I, O> UnsafeUnpin for AsyncLoadBalancer<I, O>
impl<I, O> UnwindSafe for AsyncLoadBalancer<I, O>
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