mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
replace syc::rwlock with tokio::rwlock
This commit is contained in:
parent
984e912542
commit
36e338ddde
@ -18,6 +18,7 @@ protobuf = {version = "2.18.0"}
|
|||||||
unicode-segmentation = "1.7.1"
|
unicode-segmentation = "1.7.1"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
log = "0.4.14"
|
log = "0.4.14"
|
||||||
|
tokio = {version = "1.6.0", features = ["sync"]}
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
flowy-test = { path = "../flowy-test" }
|
flowy-test = { path = "../flowy-test" }
|
@ -4,11 +4,8 @@ use crate::{
|
|||||||
services::{doc_controller::DocController, file_manager::FileManager},
|
services::{doc_controller::DocController, file_manager::FileManager},
|
||||||
};
|
};
|
||||||
use flowy_dispatch::prelude::*;
|
use flowy_dispatch::prelude::*;
|
||||||
use std::{
|
use std::{convert::TryInto, path::Path, sync::Arc};
|
||||||
convert::TryInto,
|
use tokio::sync::RwLock;
|
||||||
path::Path,
|
|
||||||
sync::{Arc, RwLock},
|
|
||||||
};
|
|
||||||
|
|
||||||
pub async fn create_doc(
|
pub async fn create_doc(
|
||||||
data: Data<CreateDocRequest>,
|
data: Data<CreateDocRequest>,
|
||||||
@ -16,7 +13,7 @@ pub async fn create_doc(
|
|||||||
manager: Unit<RwLock<FileManager>>,
|
manager: Unit<RwLock<FileManager>>,
|
||||||
) -> ResponseResult<DocDescription, EditorError> {
|
) -> ResponseResult<DocDescription, EditorError> {
|
||||||
let params: CreateDocParams = data.into_inner().try_into()?;
|
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
|
let doc_desc = controller
|
||||||
.create_doc(params, path.to_str().unwrap())
|
.create_doc(params, path.to_str().unwrap())
|
||||||
.await?;
|
.await?;
|
||||||
@ -33,7 +30,7 @@ pub async fn read_doc(
|
|||||||
|
|
||||||
let content = manager
|
let content = manager
|
||||||
.write()
|
.write()
|
||||||
.unwrap()
|
.await
|
||||||
.open(Path::new(&desc.path), desc.id.clone())?;
|
.open(Path::new(&desc.path), desc.id.clone())?;
|
||||||
|
|
||||||
let doc = Doc { desc, content };
|
let doc = Doc { desc, content };
|
||||||
@ -52,7 +49,7 @@ pub async fn update_doc(
|
|||||||
let doc_desc = controller.read_doc(¶ms.id).await?;
|
let doc_desc = controller.read_doc(¶ms.id).await?;
|
||||||
manager
|
manager
|
||||||
.write()
|
.write()
|
||||||
.unwrap()
|
.await
|
||||||
.save(Path::new(&doc_desc.path), &s, params.id.clone());
|
.save(Path::new(&doc_desc.path), &s, params.id.clone());
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,8 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use flowy_database::DBConnection;
|
use flowy_database::DBConnection;
|
||||||
use flowy_dispatch::prelude::*;
|
use flowy_dispatch::prelude::*;
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::Arc;
|
||||||
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
pub trait EditorDatabase: Send + Sync {
|
pub trait EditorDatabase: Send + Sync {
|
||||||
fn db_connection(&self) -> Result<DBConnection, EditorError>;
|
fn db_connection(&self) -> Result<DBConnection, EditorError>;
|
||||||
|
Loading…
Reference in New Issue
Block a user