Skip to content

Commit

Permalink
Use cross platform interrupt handler (#1178)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarrencev authored Nov 10, 2023
1 parent 748f5dc commit be16762
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
23 changes: 23 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/torii/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ base64 = "0.21.2"
camino.workspace = true
chrono.workspace = true
clap.workspace = true
ctrlc = { version = "3.4", features = [ "termination" ] }
dojo-types = { path = "../../dojo-types" }
dojo-world = { path = "../../dojo-world" }
either = "1.9.0"
futures.workspace = true
http = "0.2.9"
http-body = "0.4.5"
hyper-reverse-proxy = { git = "https://github.com/tarrencev/hyper-reverse-proxy" }
Expand Down
21 changes: 5 additions & 16 deletions crates/torii/server/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ use sqlx::SqlitePool;
use starknet::core::types::FieldElement;
use starknet::providers::jsonrpc::HttpTransport;
use starknet::providers::JsonRpcClient;
use tokio::signal::ctrl_c;
#[cfg(target_family = "unix")]
use tokio::signal::unix::{signal, SignalKind};
use tokio::sync::broadcast;
use tokio::sync::broadcast::Sender;
use tokio_stream::StreamExt;
Expand Down Expand Up @@ -80,12 +77,11 @@ async fn main() -> anyhow::Result<()> {
// Setup cancellation for graceful shutdown
let (shutdown_tx, _) = broadcast::channel(1);

let sigint = ctrl_c();

#[cfg(target_family = "unix")]
let mut sigterm = signal(SignalKind::terminate())?;
#[cfg(target_family = "windows")]
let (_, sigterm) = futures::channel::mpsc::unbounded::<()>();
let shutdown_tx_clone = shutdown_tx.clone();
ctrlc::set_handler(move || {
let _ = shutdown_tx_clone.send(());
})
.expect("Error setting Ctrl-C handler");

let database_url = format!("sqlite:{}", &args.database);
let options = SqliteConnectOptions::from_str(&database_url)?.create_if_missing(true);
Expand Down Expand Up @@ -150,13 +146,6 @@ async fn main() -> anyhow::Result<()> {
info!("Graphql playground: {}\n", format!("http://{}/graphql", addr));

tokio::select! {
_ = sigterm.recv() => {
let _ = shutdown_tx.send(());
}
_ = sigint => {
let _ = shutdown_tx.send(());
}

_ = engine.start() => {},
_ = proxy_server.start(shutdown_tx.subscribe()) => {},
_ = graphql_server => {},
Expand Down

0 comments on commit be16762

Please sign in to comment.