mirror of
https://git.asonix.dog/asonix/pict-rs.git
synced 2024-11-28 12:31:00 +00:00
Enable running on bare tokio
This commit is contained in:
parent
7f5cbc4571
commit
4a45aa889c
2 changed files with 31 additions and 7 deletions
|
@ -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;
|
||||
|
|
31
src/main.rs
31
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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue