2
0
Fork 0
mirror of https://git.asonix.dog/asonix/pict-rs synced 2024-12-22 19:31:35 +00:00

Enable running on bare tokio

This commit is contained in:
asonix 2023-10-07 11:48:58 -05:00
parent 7f5cbc4571
commit 4a45aa889c
2 changed files with 31 additions and 7 deletions

View file

@ -2072,6 +2072,13 @@ impl PictRsConfiguration {
Ok(self) 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 /// Run the pict-rs application
pub async fn run(self) -> color_eyre::Result<()> { pub async fn run(self) -> color_eyre::Result<()> {
let PictRsConfiguration { config, operation } = self; let PictRsConfiguration { config, operation } = self;

View file

@ -1,9 +1,26 @@
fn main() -> color_eyre::Result<()> { fn main() -> color_eyre::Result<()> {
actix_web::rt::System::new().block_on(async move { #[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()? pict_rs::PictRsConfiguration::build_default()?
.install_tracing()? .install_tracing()?
.install_metrics()? .install_metrics()?
.run() .run_on_localset()
.await .await
})
} }