Struct slottle::ThrottlePoolBuilder[][src]

pub struct ThrottlePoolBuilder<K: Hash + Eq> { /* fields omitted */ }

Use to build a ThrottlePool.

Created by ThrottlePool::builder() API.

Implementations

impl<K: Hash + Eq> ThrottlePoolBuilder<K>[src]

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

Set interval of throttles in this pool.

The default value is no delay (Duration::new(0, 0))

Example

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

// fixed interval: 10ms
let pool: ThrottlePool<bool> = ThrottlePool::builder()
    .interval(Duration::from_millis(10))
    .build().unwrap();

// random interval between: 10ms ~ 0ms
let pool: ThrottlePool<bool> = ThrottlePool::builder()
    .interval(|| Duration::from_millis(10).mul_f64(rand::random()))
    .build().unwrap();

// increasing delay if failed continuously
let pool: ThrottlePool<bool> = ThrottlePool::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
    ))
    .build().unwrap();

// use pre-defined interval algorithm
let pool: ThrottlePool<bool> = ThrottlePool::builder()
    .interval(slottle::fibonacci(
        Duration::from_millis(10),
        Duration::from_secs(2),
    ))
    .build().unwrap();

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

Set concurrent, default value is 1.

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

Create a new ThrottlePool with current configuration.

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

Trait Implementations

impl<K: Hash + Eq> Debug for ThrottlePoolBuilder<K>[src]

impl<K: Hash + Eq> Default for ThrottlePoolBuilder<K>[src]

Auto Trait Implementations

impl<K> !RefUnwindSafe for ThrottlePoolBuilder<K>

impl<K> Send for ThrottlePoolBuilder<K> where
    K: Send

impl<K> Sync for ThrottlePoolBuilder<K> where
    K: Sync

impl<K> Unpin for ThrottlePoolBuilder<K> where
    K: Unpin

impl<K> !UnwindSafe for ThrottlePoolBuilder<K>

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.