-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/agent-rework' into oauth-session
- Loading branch information
Showing
23 changed files
with
362 additions
and
344 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
pub mod resolver; | ||
pub mod store; | ||
pub mod types; | ||
|
||
pub mod resolver; | ||
pub mod store; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,46 @@ | ||
use super::MapStore; | ||
use super::Store; | ||
use std::collections::HashMap; | ||
use std::fmt::Debug; | ||
use std::hash::Hash; | ||
use std::sync::{Arc, Mutex}; | ||
use std::sync::Arc; | ||
use thiserror::Error; | ||
use tokio::sync::Mutex; | ||
|
||
#[derive(Error, Debug)] | ||
#[error("memory store error")] | ||
pub struct Error; | ||
|
||
// TODO: LRU cache? | ||
#[derive(Clone)] | ||
pub struct MemoryMapStore<K, V> { | ||
pub struct MemoryStore<K, V> { | ||
store: Arc<Mutex<HashMap<K, V>>>, | ||
} | ||
|
||
impl<K, V> Default for MemoryMapStore<K, V> { | ||
impl<K, V> Default for MemoryStore<K, V> { | ||
fn default() -> Self { | ||
Self { store: Arc::new(Mutex::new(HashMap::new())) } | ||
} | ||
} | ||
|
||
impl<K, V> MapStore<K, V> for MemoryMapStore<K, V> | ||
impl<K, V> Store<K, V> for MemoryStore<K, V> | ||
where | ||
K: Debug + Eq + Hash + Send + Sync + 'static, | ||
V: Debug + Clone + Send + Sync + 'static, | ||
{ | ||
type Error = Error; | ||
|
||
async fn get(&self, key: &K) -> Result<Option<V>, Self::Error> { | ||
Ok(self.store.lock().unwrap().get(key).cloned()) | ||
Ok(self.store.lock().await.get(key).cloned()) | ||
} | ||
async fn set(&self, key: K, value: V) -> Result<(), Self::Error> { | ||
self.store.lock().unwrap().insert(key, value); | ||
self.store.lock().await.insert(key, value); | ||
Ok(()) | ||
} | ||
async fn del(&self, key: &K) -> Result<(), Self::Error> { | ||
self.store.lock().unwrap().remove(key); | ||
self.store.lock().await.remove(key); | ||
Ok(()) | ||
} | ||
async fn clear(&self) -> Result<(), Self::Error> { | ||
self.store.lock().unwrap().clear(); | ||
self.store.lock().await.clear(); | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.