JavaScript is disabled, refresh for a better experience. ambee/giterated

ambee/giterated

Git repository hosting, collaboration, and discovery for the Fediverse.

Fixed imports!

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨ef0e853

⁨giterated-daemon/src/federation/connections.rs⁩ - ⁨650⁩ bytes
Raw
1 use std::collections::HashMap;
2
3 use anyhow::Error;
4 use giterated_api::DaemonConnectionPool;
5 use giterated_models::instance::Instance;
6
7 #[derive(Default)]
8 pub struct InstanceConnections {
9 pools: HashMap<Instance, DaemonConnectionPool>,
10 }
11
12 impl InstanceConnections {
13 pub fn get_or_open(&mut self, instance: &Instance) -> Result<DaemonConnectionPool, Error> {
14 if let Some(pool) = self.pools.get(instance) {
15 Ok(pool.clone())
16 } else {
17 let pool = DaemonConnectionPool::connect(instance.clone()).unwrap();
18 self.pools.insert(instance.clone(), pool.clone());
19
20 Ok(pool)
21 }
22 }
23 }
24