浏览代码

replace syc::rwlock with tokio::rwlock

appflowy 3 年之前
父节点
当前提交
36e338ddde

+ 1 - 0
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" }

+ 5 - 8
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());
         },
     }

+ 2 - 1
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>;