Files
server/src/core/task.rs
Schmarni e3321c54fb refactor: IT RUNS!
Signed-off-by: Schmarni <marnistromer@gmail.com>
2024-12-31 22:45:16 +01:00

25 lines
526 B
Rust

use color_eyre::eyre::Result;
use std::future::Future;
use tokio::task::JoinHandle;
use crate::TOKIO;
#[allow(unused_variables)]
pub fn new<
F: FnOnce() -> S,
S: AsRef<str>,
A: Future<Output = O> + Send + 'static,
O: Send + 'static,
>(
name_fn: F,
async_future: A,
) -> Result<JoinHandle<O>> {
#[cfg(not(feature = "profile_tokio"))]
let result = Ok(TOKIO.spawn(async_future));
#[cfg(feature = "profile_tokio")]
let result = tokio::task::Builder::new()
.name(name_fn().as_ref())
.spawn(async_future);
result
}