+ struct Outstanding {
+ reply: tokio::sync::oneshot::Sender<WebResponse>,
+ max_requests_outstanding: u32,
+ }
+ let mut outstanding: VecDeque<Outstanding> = default();
+ let downbound: VecDeque<(/*xxx*/)> = default();
+
+ loop {
+ if let Some(ret) = {
+ if ! downbound.is_empty() {
+ outstanding.pop_front()
+ } else if let Some((i,_)) = outstanding.iter().enumerate().find({
+ |(_,o)| outstanding.len() > o.max_requests_outstanding.sat()
+ }) {
+ Some(outstanding.remove(i).unwrap())
+ } else {
+ None
+ }
+ } {
+ ret.reply.send(Ok(() /* dummy */))
+ .unwrap_or_else(|_: WebResponse| () /* oh dear */ /* xxx trace? */);
+ }
+
+ select!{
+ req = web.recv() =>
+ {
+ let req = req.ok_or_else(|| anyhow!("webservers all shut down!"))?;
+ outstanding.push_back(Outstanding {
+ reply: req.reply,
+ max_requests_outstanding: 42, // xxx
+ });
+ }
+ }
+ }
+ //Err(anyhow!("xxx"))