♻️ Remove Option<>

main
_ 2020-11-05 21:44:32 -06:00
parent 7e697df35a
commit 3a50424a35
5 changed files with 17 additions and 22 deletions

View File

@ -50,6 +50,6 @@ async fn main () -> Result <(), Box <dyn Error>> {
relay::run_relay (
Arc::new (RelayState::from (&config_file)),
Some (rx)
rx
).await
}

View File

@ -27,5 +27,5 @@ async fn main () -> Result <(), Box <dyn Error>> {
toml::from_str (&config_s).unwrap_or_else (|_| panic! ("Can't parse {:?} as TOML", config_file_path))
};
ptth::server::main (config_file, None).await
ptth::server::run_server (config_file, None).await
}

View File

@ -113,7 +113,7 @@ mod tests {
let relay_state_2 = relay_state.clone ();
let (stop_relay_tx, stop_relay_rx) = oneshot::channel ();
let task_relay = spawn (async move {
relay::run_relay (relay_state_2, Some (stop_relay_rx)).await.unwrap ();
relay::run_relay (relay_state_2, stop_relay_rx).await.unwrap ();
});
assert! (relay_state.list_servers ().await.is_empty ());
@ -130,7 +130,7 @@ mod tests {
let task_server = {
let stop_server_atomic = stop_server_atomic.clone ();
spawn (async move {
server::main (config_file, Some (stop_server_atomic)).await.unwrap ();
server::run_server (config_file, Some (stop_server_atomic)).await.unwrap ();
})
};

View File

@ -397,7 +397,7 @@ use tracing::info;
pub async fn run_relay (
state: Arc <RelayState>,
shutdown_oneshot: Option <oneshot::Receiver <()>>
shutdown_oneshot: oneshot::Receiver <()>
)
-> Result <(), Box <dyn Error>>
{
@ -433,22 +433,17 @@ pub async fn run_relay (
let server = Server::bind (&addr)
.serve (make_svc);
match shutdown_oneshot {
Some (rx) => {
info! ("Configured for graceful shutdown");
server.with_graceful_shutdown (async {
rx.await.ok ();
info! ("Configured for graceful shutdown");
server.with_graceful_shutdown (async {
shutdown_oneshot.await.ok ();
state.response_rendezvous.clear ();
state.response_rendezvous.clear ();
let mut request_rendezvoux = state.request_rendezvous.lock ().await;
request_rendezvoux.clear ();
let mut request_rendezvoux = state.request_rendezvous.lock ().await;
request_rendezvoux.clear ();
info! ("Received graceful shutdown");
}).await?
},
None => server.await?,
};
info! ("Received graceful shutdown");
}).await?;
info! ("Exiting");
Ok (())

View File

@ -115,7 +115,7 @@ use std::sync::atomic::{
use tracing::info;
pub async fn main (
pub async fn run_server (
config_file: ConfigFile,
shutdown_atomic: Option <Arc <AtomicBool>>
)