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()) }