replace syc::rwlock with tokio::rwlock

This commit is contained in:
appflowy 2021-07-23 15:00:13 +08:00
parent 984e912542
commit 36e338ddde
3 changed files with 8 additions and 9 deletions

View File

@ -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" }

View File

@ -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());
},
}

View File

@ -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>;