qorb/
resolver.rs

1//! The interface for the resolver, which finds backends.
2
3use crate::backend::{self, Backend};
4
5use async_trait::async_trait;
6use std::collections::BTreeMap;
7use std::sync::Arc;
8use tokio::sync::watch;
9
10pub type AllBackends = Arc<BTreeMap<backend::Name, Backend>>;
11
12/// Translates a service name into a set of backends.
13///
14/// The resolver is responsible for knowing which [crate::service::Name]
15/// it is resolving. It is responsible for reporting the set of
16/// all possible backends, but not reporting nor tracking their health.
17#[async_trait]
18pub trait Resolver: Send + Sync {
19    /// Start running a resolver.
20    ///
21    /// Returns a receiver to track ongoing activity.
22    fn monitor(&mut self) -> watch::Receiver<AllBackends>;
23
24    /// Cleanly terminates the server.
25    ///
26    /// This ensures that background tasks, if they exist, have stopped.
27    async fn terminate(&mut self) {}
28}
29
30/// Helper type for anything that implements the Resolver interface.
31pub type BoxedResolver = Box<dyn Resolver>;