Module burger::buffer

source ·
Expand description

The ServiceExt::buffer combinator returns Buffer, whose Service::acquire immediately resolves until the buffer is at maximum capacity, at which point it defers to the inner service’s Service::acquire. The buffer is drained when the inner service’s permit becomes available.

§Example

use burger::*;

let svc = service_fn(|x| async move {
    sleep(Duration::from_secs(1)).await;
    x + 1
})
.concurrency_limit(1)
.buffer(2)
.load_shed();
let (a, b, c, d) = join! {
    svc.oneshot(9),
    svc.oneshot(2),
    svc.oneshot(1),
    svc.oneshot(5)
};
assert_eq!(a, Ok(10));
assert_eq!(b, Ok(3));
assert_eq!(c, Ok(2));
assert_eq!(d, Err(5));

§Load

The Load::load on Buffer defers to the inner service.

Structs§