use super::{query, Content, DynDir, VPath};

#[derive(Debug, Clone)]
pub struct AsyncDir {
    inner: DynDir,
}

impl AsyncDir {
    pub fn new(inner: DynDir) -> Self {
        Self { inner }
    }

    pub fn sync(&self) -> &DynDir {
        &self.inner
    }

    pub async fn content(&self, path: &VPath) -> Option<Content> {
        let this = self.clone();
        let path = path.to_owned();
        // NOTE: Performance impact of spawning a blocking task may be a bit high in case
        // we add caching.
        // Measure throughput here.
        tokio::task::spawn_blocking(move || query::<Content>(&this.inner, &path))
            .await
            .unwrap()
    }
}
