#![allow(unreachable_pub)]
use crate::{runtime::context, task::JoinHandle};
use std::future::Future;
#[derive(Default, Debug)]
pub struct Builder<'a> {
name: Option<&'a str>,
}
impl<'a> Builder<'a> {
pub fn new() -> Self {
Self::default()
}
pub fn name(&self, name: &'a str) -> Self {
Self { name: Some(name) }
}
#[cfg_attr(tokio_track_caller, track_caller)]
pub fn spawn<Fut>(self, future: Fut) -> JoinHandle<Fut::Output>
where
Fut: Future + Send + 'static,
Fut::Output: Send + 'static,
{
super::spawn::spawn_inner(future, self.name)
}
#[cfg_attr(tokio_track_caller, track_caller)]
pub fn spawn_local<Fut>(self, future: Fut) -> JoinHandle<Fut::Output>
where
Fut: Future + 'static,
Fut::Output: 'static,
{
super::local::spawn_local_inner(future, self.name)
}
#[cfg_attr(tokio_track_caller, track_caller)]
pub fn spawn_blocking<Function, Output>(self, function: Function) -> JoinHandle<Output>
where
Function: FnOnce() -> Output + Send + 'static,
Output: Send + 'static,
{
context::current().spawn_blocking_inner(function, self.name)
}
}