Files
server/src/core/task.rs
Thomas Colliers f0a494392a Formatting
2025-08-19 03:52:09 +02:00

24 lines
537 B
Rust

use color_eyre::eyre::Result;
use std::future::Future;
use tokio::task::JoinHandle;
#[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::task::spawn(async_future));
#[cfg(feature = "profile_tokio")]
let result = tokio::task::Builder::new()
.name(name_fn().as_ref())
.spawn(async_future)
.map_err(Into::into);
result
}