use crate::{CrdtManager, CrdtResult};
use std::sync::Arc;
pub struct CoreServices {
crdt_manager: Arc<CrdtManager>,
}
impl CoreServices {
pub async fn bootstrap(db_path: impl AsRef<std::path::Path>) -> CrdtResult<Self> {
let crdt_manager = Arc::new(CrdtManager::new(db_path).await?);
Ok(Self { crdt_manager })
}
pub fn crdt_manager(&self) -> &Arc<CrdtManager> {
&self.crdt_manager
}
}
#[cfg(test)]
mod tests {
use super::*;
use tempfile::tempdir;
#[tokio::test]
async fn test_bootstrap_services() {
let temp_dir = tempdir().unwrap();
let db_path = temp_dir.path().join("test.db");
let services = CoreServices::bootstrap(&db_path).await.unwrap();
assert!(Arc::strong_count(services.crdt_manager()) >= 1);
}
}