This commit is contained in:
Vecna 2024-05-25 17:27:39 -04:00
parent c4828d691f
commit fc03309af2
2 changed files with 6 additions and 22 deletions

View File

@ -5,7 +5,7 @@
use troll_patrol::{
extra_info::ExtraInfo,
get_date, increment_simulated_date,
increment_simulated_date,
simulation::{
bridge::Bridge,
censor::{Censor, Hides::*, Speed::*, Totality::*},
@ -120,10 +120,8 @@ pub async fn main() {
let mut tp = 0;
// Main loop
for _ in 0..config.num_days {
let la_net = HyperNet {
hostname: format!("http://localhost:{}", config.la_port),
};
for day in 1..=config.num_days {
println!("Starting day {} of the simulation", day);
// USER TASKS

View File

@ -11,7 +11,7 @@ use serde_json::json;
use std::{collections::HashSet, convert::Infallible, net::SocketAddr, time::Duration};
use tokio::{
spawn,
sync::{broadcast, mpsc, oneshot},
sync::{mpsc, oneshot},
time::sleep,
};
@ -44,12 +44,8 @@ async fn serve_extra_infos(
pub async fn server() {
let (context_tx, context_rx) = mpsc::channel(32);
let request_tx = context_tx.clone();
let shutdown_cmd_tx = context_tx.clone();
let (shutdown_tx, mut shutdown_rx) = broadcast::channel(16);
let kill_context = shutdown_tx.subscribe();
let context_manager =
spawn(async move { create_context_manager(context_rx, kill_context).await });
spawn(async move { create_context_manager(context_rx).await });
let addr = SocketAddr::from(([127, 0, 0, 1], 8004));
let make_svc = make_service_fn(move |_conn: &AddrStream| {
@ -75,13 +71,9 @@ pub async fn server() {
}
}
async fn create_context_manager(
context_rx: mpsc::Receiver<Command>,
mut kill: broadcast::Receiver<()>,
) {
async fn create_context_manager(context_rx: mpsc::Receiver<Command>) {
tokio::select! {
create_context = context_manager(context_rx) => create_context,
_ = kill.recv() => {println!("Shut down context_manager");},
}
}
@ -98,9 +90,6 @@ async fn context_manager(mut context_rx: mpsc::Receiver<Command>) {
}
sleep(Duration::from_millis(1)).await;
}
Shutdown { shutdown_sig } => {
drop(shutdown_sig);
}
}
}
}
@ -111,9 +100,6 @@ enum Command {
req: Request<Body>,
sender: oneshot::Sender<Result<Response<Body>, Infallible>>,
},
Shutdown {
shutdown_sig: broadcast::Sender<()>,
},
}
fn add_extra_infos(extra_infos_pages: &mut Vec<String>, request: Bytes) -> Response<Body> {