use std::sync::Arc;
#[derive(Debug, Clone)]
pub struct Handle {
inner: Arc<HandleInner>,
}
impl Handle {
pub fn new(rt: tokio::runtime::Handle, tpc: tokio_util::task::LocalPoolHandle) -> Self {
Self {
inner: Arc::new(HandleInner { rt, tpc }),
}
}
pub fn from_current(size: usize) -> std::result::Result<Self, tokio::runtime::TryCurrentError> {
Ok(Self::new(
tokio::runtime::Handle::try_current()?,
tokio_util::task::LocalPoolHandle::new(size),
))
}
pub fn main(&self) -> &tokio::runtime::Handle {
&self.inner.rt
}
pub fn local_pool(&self) -> &tokio_util::task::LocalPoolHandle {
&self.inner.tpc
}
}
#[derive(Debug)]
struct HandleInner {
rt: tokio::runtime::Handle,
tpc: tokio_util::task::LocalPoolHandle,
}