From 3f5bc1d3115bf1feeb7d3c0b5d58da2779650ad1 Mon Sep 17 00:00:00 2001 From: asonix Date: Sat, 7 Oct 2023 12:22:17 -0500 Subject: [PATCH] Build same pict-rs config for either runtime option --- src/lib.rs | 3 +++ src/main.rs | 28 ++++++++++++---------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b8a6a4f..c485ba2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2080,6 +2080,9 @@ impl PictRsConfiguration { } /// Run the pict-rs application + /// + /// This must be called from within a tokio `LocalSet`, which is created by default for + /// actix-rt runtimes, and by tokio_uring pub async fn run(self) -> color_eyre::Result<()> { let PictRsConfiguration { config, operation } = self; diff --git a/src/main.rs b/src/main.rs index 7bf001d..5f8ee4d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,24 +1,20 @@ fn main() -> color_eyre::Result<()> { - run() + let config = pict_rs::PictRsConfiguration::build_default()? + .install_tracing()? + .install_metrics()?; + + run(config) } #[cfg(feature = "io-uring")] -fn run() -> color_eyre::Result<()> { - tokio_uring::start(async move { - pict_rs::PictRsConfiguration::build_default()? - .install_tracing()? - .install_metrics()? - .run() - .await - }) +fn run(config: pict_rs::PictRsConfiguration) -> color_eyre::Result<()> { + tokio_uring::start(config.run()) } #[cfg(not(feature = "io-uring"))] -#[tokio::main] -async fn run() -> color_eyre::Result<()> { - pict_rs::PictRsConfiguration::build_default()? - .install_tracing()? - .install_metrics()? - .run_on_localset() - .await +fn run(config: pict_rs::PictRsConfiguration) -> color_eyre::Result<()> { + tokio::runtime::Builder::new_multi_thread() + .enable_all() + .build()? + .block_on(config.run()) }