#[derive(Debug)]
struct Global {
config: config::InstanceConfigGlobal,
- all_clients: HashMap<ClientName, ClientHandles>,
+ all_clients: HashMap<ClientName, Client>,
}
#[derive(Debug)]
-struct ClientHandles {
+struct Client {
ic: Arc<InstanceConfig>,
web: tokio::sync::mpsc::Sender<WebRequest>,
}
&opts.config, &opts.log, |ics|
{
let global_config = config::InstanceConfigGlobal::from(&ics);
- let ipif = Ipif::start(&global_config.ipif, None)?;
- let all_clients = ics.into_iter().map(|ic| {
- let ic = Arc::new(ic);
+ let ipif = Ipif::start(&global_config.ipif, None)?;
- let (web_send, web_recv) = mpsc::channel(
+ let ics = ics.into_iter().map(Arc::new).collect_vec();
+ let (client_handles_send, client_handles_recv) = ics.iter()
+ .map(|_ic| mpsc::channel(
5 // xxx should me max_requests_outstanding but that's
- // marked client-only so needs rework
- );
+ // marked client-only so needs rework
+ )).unzip::<_,_,Vec<_>,Vec<_>>();
+
+ let all_clients = izip!(
+ ics.into_iter(),
+ client_handles_send,
+ client_handles_recv,
+ ).map(|(ic, web_send, web_recv)| {
+ let r = (ic.link.client,
+ Client {
+ ic: ic.clone(),
+ web: web_send,
+ });
let ic_ = ic.clone();
tasks.push((tokio::spawn(async move {
run_client(ic_, web_recv).await.void_unwrap_err()
}), format!("client {}", &ic)));
- (ic.link.client,
- ClientHandles {
- ic,
- web: web_send,
- })
+ r
}).collect();
let global = Arc::new(Global {
config: global_config,