Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvement: replace async lock to std mutex in await-tree registry #74

Merged
merged 1 commit into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/await_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ use await_tree::{Registry, TreeRoot};

use once_cell::sync::Lazy;
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::Arc;

use tokio::sync::Mutex;
use std::sync::{Arc, Mutex};

type AwaitTreeRegistryRef = Arc<Mutex<Registry<u64>>>;

Expand All @@ -44,7 +42,7 @@ impl AwaitTreeInner {
pub async fn register(&self, msg: String) -> TreeRoot {
let id = self.next_id.fetch_add(1, Ordering::SeqCst);
let msg = format!("actor=[{}], {}", id, msg);
self.inner.lock().await.register(id, msg)
self.inner.lock().unwrap().register(id, msg)
}

pub fn get_inner(&self) -> AwaitTreeRegistryRef {
Expand Down
2 changes: 1 addition & 1 deletion src/http/await_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl Handler for AwaitTreeHandler {
fn get_route_method(&self) -> RouteMethod {
get(make(|_| async {
let registry_cloned = AWAIT_TREE_REGISTRY.clone().get_inner();
let registry = registry_cloned.lock().await;
let registry = registry_cloned.lock().unwrap();
let mut dynamic_string = String::new();
for (_, tree) in registry.iter() {
let raw_tree = format!("{}", tree);
Expand Down