From 36e338dddef7d244a34ad46dee26b72e55c207c2 Mon Sep 17 00:00:00 2001 From: appflowy Date: Fri, 23 Jul 2021 15:00:13 +0800 Subject: [PATCH] replace syc::rwlock with tokio::rwlock --- rust-lib/flowy-editor/Cargo.toml | 1 + rust-lib/flowy-editor/src/handlers/doc_handler.rs | 13 +++++-------- rust-lib/flowy-editor/src/module.rs | 3 ++- 3 files changed, 8 insertions(+), 9 deletions(-) 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, @@ -16,7 +13,7 @@ pub async fn create_doc( manager: Unit>, ) -> ResponseResult { let params: CreateDocParams = data.into_inner().try_into()?; - let path = manager.read().unwrap().make_file_path(¶ms.id); + let path = manager.read().await.make_file_path(¶ms.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(¶ms.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;