Skip to content

Commit

Permalink
feat: wrap OperatorRegistry in Arc Mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgehermo9 committed Jan 5, 2025
1 parent e7215b4 commit b6dd1dc
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions core/src/types/operator/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

use std::cell::LazyCell;
use std::collections::HashMap;
use std::sync::{Arc, Mutex};

use http::Uri;

Expand All @@ -35,21 +36,24 @@ pub type OperatorFactory = fn(&str, HashMap<String, String>) -> Result<Operator>
// TODO: create an static registry? or a global() method of OperatorRegistry that lazily initializes the registry?
// Register only services in `Scheme::enabled()`

#[derive(Clone, Debug)]
pub struct OperatorRegistry {
// TODO: add Arc<Mutex<...>> to make it cheap to clone + thread safe? or is it not needed?
registry: HashMap<String, OperatorFactory>,
registry: Arc<Mutex<HashMap<String, OperatorFactory>>>,
}

impl OperatorRegistry {
pub fn new() -> Self {
Self {
registry: HashMap::new(),
registry: Default::default(),
}
}

pub fn register(&mut self, scheme: &str, factory: OperatorFactory) {
// TODO: should we receive a `&str` or a `String`? we are cloning it anyway
self.registry.insert(scheme.to_string(), factory);
self.registry
.lock()
.expect("poisoned lock")
.insert(scheme.to_string(), factory);
}

pub fn parse(
Expand Down

0 comments on commit b6dd1dc

Please sign in to comment.