Module burger::load_shed

source ·
Expand description

The ServiceExt::load_shed combinator returns LoadShed, which causes Service::acquire to immediately return Some(permit) when the inner permit is ready and immediately return None otherwise.

This may be used to discard any work which cannot be permitted at the time Service::acquire is called.

This is a relative of ServiceExt::depressurize, which immediately accepts all work.

§Example

use burger::*;

async fn main() {
let svc = service_fn(|x| async move {
    sleep(Duration::from_secs(1)).await;
    x + 5
})
.concurrency_limit(1)
.load_shed();
let (a, b) = tokio::join! {
    svc.oneshot(32),
    svc.oneshot(31)
};
assert_eq!(a, Ok(37));
assert_eq!(b, Err(31));

§Load

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

Structs§