Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

replace syc::rwlock with tokio::rwlock

appflowy36e338dddef7
diff --git a/rust-lib/flowy-editor/Cargo.toml b/rust-lib/flowy-editor/Cargo.toml
index 693983f09b..21b2c3eb65 100644
--- a/rust-lib/flowy-editor/Cargo.toml
+++ b/rust-lib/flowy-editor/Cargo.toml
@@ -18,6 +18,7 @@ protobuf = {version = "2.18.0"}
unicode-segmentation = "1.7.1"
lazy_static = "1.4.0"
log = "0.4.14"
+tokio = {version = "1.6.0", features = ["sync"]}
[dev-dependencies]
flowy-test = { path = "../flowy-test" }
\ No newline at end of file
diff --git a/rust-lib/flowy-editor/src/handlers/doc_handler.rs b/rust-lib/flowy-editor/src/handlers/doc_handler.rs
index ad7d7fa9ec..419bc37ecd 100644
--- a/rust-lib/flowy-editor/src/handlers/doc_handler.rs
+++ b/rust-lib/flowy-editor/src/handlers/doc_handler.rs
@@ -4,11 +4,8 @@ use crate::{
services::{doc_controller::DocController, file_manager::FileManager},
};
use flowy_dispatch::prelude::*;
-use std::{
- convert::TryInto,
- path::Path,
- sync::{Arc, RwLock},
-};
+use std::{convert::TryInto, path::Path, sync::Arc};
+use tokio::sync::RwLock;
pub async fn create_doc(
data: Data<CreateDocRequest>,
@@ -16,7 +13,7 @@ pub async fn create_doc(
manager: Unit<RwLock<FileManager>>,
) -> ResponseResult<DocDescription, EditorError> {
let params: CreateDocParams = data.into_inner().try_into()?;
- let path = manager.read().unwrap().make_file_path(&params.id);
+ let path = manager.read().await.make_file_path(&params.id);
let doc_desc = controller
.create_doc(params, path.to_str().unwrap())
.await?;
@@ -33,7 +30,7 @@ pub async fn read_doc(
let content = manager
.write()
- .unwrap()
+ .await
.open(Path::new(&desc.path), desc.id.clone())?;
let doc = Doc { desc, content };
@@ -52,7 +49,7 @@ pub async fn update_doc(
let doc_desc = controller.read_doc(&params.id).await?;
manager
.write()
- .unwrap()
+ .await
.save(Path::new(&doc_desc.path), &s, params.id.clone());
},
}
diff --git a/rust-lib/flowy-editor/src/module.rs b/rust-lib/flowy-editor/src/module.rs
index 6747b1017f..3cded4a0b6 100644
--- a/rust-lib/flowy-editor/src/module.rs
+++ b/rust-lib/flowy-editor/src/module.rs
@@ -9,7 +9,8 @@ use crate::{
};
use flowy_database::DBConnection;
use flowy_dispatch::prelude::*;
-use std::sync::{Arc, RwLock};
+use std::sync::Arc;
+use tokio::sync::RwLock;
pub trait EditorDatabase: Send + Sync {
fn db_connection(&self) -> Result<DBConnection, EditorError>;