Expand description
Given a collection of some services, select
constructs a Service
which uses the
first permit available.
§Example
use burger::*;
pub struct Wait(u64);
#[non_exhaustive]
pub struct WaitPermit<'a>(&'a u64);
impl Service<u64> for Wait {
type Response = u64;
type Permit<'a> = WaitPermit<'a>;
async fn acquire(&self) -> Self::Permit<'_> {
sleep(Duration::from_secs(self.0)).await;
WaitPermit(&self.0)
}
async fn call(permit: Self::Permit<'_>, request: u64) -> u64 {
permit.0 * request
}
}
async fn main() {
let svcs: Vec<_> = (0..10).map(Wait).collect();
let svc = select(svcs);
let response = svc.oneshot(7).await;
assert_eq!(0, response);
§Load
This has no Load
implementation.
Structs§
Functions§
- Constructs a
Service
from a collection (IntoIterator
must be implemented for its reference) of services whoseService::call
is the by the first available child.