From 4a45aa889c3fee335b27f95b1a1227f897aa58b4 Mon Sep 17 00:00:00 2001 From: asonix Date: Sat, 7 Oct 2023 11:48:58 -0500 Subject: [PATCH] Enable running on bare tokio --- src/lib.rs | 7 +++++++ src/main.rs | 31 ++++++++++++++++++++++++------- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 4355488..b8a6a4f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2072,6 +2072,13 @@ impl PictRsConfiguration { Ok(self) } + /// Run the pict-rs application on a tokio `LocalSet` + /// + /// This must be called from within `tokio::main` directly + pub async fn run_on_localset(self) -> color_eyre::Result<()> { + tokio::task::LocalSet::new().run_until(self.run()).await + } + /// Run the pict-rs application pub async fn run(self) -> color_eyre::Result<()> { let PictRsConfiguration { config, operation } = self; diff --git a/src/main.rs b/src/main.rs index 0c40c24..457cd30 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,26 @@ fn main() -> color_eyre::Result<()> { - actix_web::rt::System::new().block_on(async move { - pict_rs::PictRsConfiguration::build_default()? - .install_tracing()? - .install_metrics()? - .run() - .await - }) + #[cfg(not(feature = "io-uring"))] + return run_tokio(); + + #[cfg(feature = "io-uring")] + return run_tokio_uring(); +} + +#[cfg(feature = "io-uring")] +fn run_tokio_uring() -> color_eyre::Result<()> { + tokio_uring::start(run()) +} + +#[cfg(not(feature = "io-uring"))] +#[tokio::main] +async fn run_tokio() -> color_eyre::Result<()> { + run().await +} + +async fn run() -> color_eyre::Result<()> { + pict_rs::PictRsConfiguration::build_default()? + .install_tracing()? + .install_metrics()? + .run_on_localset() + .await }