Struct slottle::ThrottleBuilder[][src]

pub struct ThrottleBuilder { /* fields omitted */ }

Use to build a Throttle.

Created by Throttle::builder() API.

Implementations

impl ThrottleBuilder[src]

pub fn interval<I>(&mut self, interval: I) -> &mut Self where
    I: Into<Interval>, 
[src]

Set interval of throttle.

Example

use slottle::{Throttle, Interval};
use std::time::Duration;
use rand;

// fixed interval: 10ms
Throttle::builder().interval(Duration::from_millis(10));

// random interval between: 10ms ~ 0ms
Throttle::builder()
    .interval(|| Duration::from_millis(10).mul_f64(rand::random()));

// increasing delay if failed continuously
Throttle::builder()
    .interval(Interval::new(
        |log| match log.unwrap().failure_count_cont() {
            0 => Duration::from_millis(10),
            1 => Duration::from_millis(30),
            2 => Duration::from_millis(50),
            3 => Duration::from_millis(70),
            _ => unreachable!(),
        },
        3,  // maximum log size
    ));

// use pre-defined algorithm
Throttle::builder()
    .interval(slottle::fibonacci(
        Duration::from_millis(10),
        Duration::from_secs(2),
    ));

pub fn concurrent(&mut self, concurrent: u32) -> &mut Self[src]

Set concurrent, default value is 1.

pub fn build(&self) -> Option<Throttle>[src]

Create a new Throttle with current configuration.

Return None if concurrent == 0 or larger than isize::MAX.

Trait Implementations

impl Debug for ThrottleBuilder[src]

Auto Trait Implementations

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.