diff --git a/core/src/types/operator/registry.rs b/core/src/types/operator/registry.rs index f85257a6a10..a7f1c441030 100644 --- a/core/src/types/operator/registry.rs +++ b/core/src/types/operator/registry.rs @@ -17,6 +17,7 @@ use std::cell::LazyCell; use std::collections::HashMap; +use std::sync::{Arc, Mutex}; use http::Uri; @@ -35,21 +36,24 @@ pub type OperatorFactory = fn(&str, HashMap) -> Result // 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> to make it cheap to clone + thread safe? or is it not needed? - registry: HashMap, + registry: Arc>>, } 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(