use std::future::Future;
use super::{JoinHandle, Spawner};
#[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) }
}
#[track_caller]
pub fn spawn<Fut>(self, future: Fut) -> JoinHandle<Fut::Output>
where
Fut: Future + Send + 'static,
Fut::Output: Send + 'static,
{
Spawner::current().spawn_inner(future, self.name)
}
#[track_caller]
pub fn spawn_local<Fut>(self, future: Fut) -> JoinHandle<Fut::Output>
where
Fut: Future + 'static,
Fut::Output: 'static,
{
Spawner::current().spawn_inner(future, self.name)
}
}