use std::future::Future;
use std::sync::Arc;
use crate::context::TreeContext;
use crate::registry::WeakRegistry;
use crate::Registry;
pub struct TreeRoot {
pub(crate) context: Arc<TreeContext>,
pub(crate) registry: WeakRegistry,
}
tokio::task_local! {
pub(crate) static ROOT: TreeRoot
}
pub(crate) fn current_context() -> Option<Arc<TreeContext>> {
ROOT.try_with(|r| r.context.clone()).ok()
}
pub(crate) fn current_registry() -> Option<Registry> {
ROOT.try_with(|r| r.registry.upgrade()).ok().flatten()
}
impl TreeRoot {
pub async fn instrument<F: Future>(self, future: F) -> F::Output {
ROOT.scope(self, future).await
}
}