42 lines
1.3 KiB
Rust
Raw Normal View History

2022-06-29 20:51:53 +08:00
use crate::manager::GridTaskSchedulerRwLock;
2022-06-29 13:44:15 +08:00
use crate::services::grid_editor::GridRevisionEditor;
2022-07-19 20:39:05 +08:00
use crate::services::tasks::{GridTaskHandler, Task, TaskContent, TaskId};
2022-06-29 13:44:15 +08:00
use flowy_error::FlowyError;
2022-06-29 20:51:53 +08:00
use futures::future::BoxFuture;
2022-06-29 13:44:15 +08:00
use lib_infra::future::BoxResultFuture;
2022-06-30 23:00:03 +08:00
pub(crate) trait GridServiceTaskScheduler: Send + Sync + 'static {
2022-06-29 20:51:53 +08:00
fn gen_task_id(&self) -> BoxFuture<TaskId>;
2022-07-19 20:39:05 +08:00
fn add_task(&self, task: Task) -> BoxFuture<()>;
2022-06-29 20:51:53 +08:00
}
2022-06-29 16:55:52 +08:00
impl GridTaskHandler for GridRevisionEditor {
2022-07-19 20:39:05 +08:00
fn handler_id(&self) -> &str {
2022-06-29 13:44:15 +08:00
&self.grid_id
}
2022-07-19 20:39:05 +08:00
fn process_content(&self, content: TaskContent) -> BoxResultFuture<(), FlowyError> {
2022-06-29 13:44:15 +08:00
Box::pin(async move {
2022-07-19 20:39:05 +08:00
match content {
2022-06-30 23:00:03 +08:00
TaskContent::Snapshot => {}
TaskContent::Filter(context) => self.filter_service.process(context).await?,
2022-06-29 13:44:15 +08:00
}
Ok(())
})
}
}
2022-06-29 20:51:53 +08:00
impl GridServiceTaskScheduler for GridTaskSchedulerRwLock {
fn gen_task_id(&self) -> BoxFuture<TaskId> {
let this = self.clone();
Box::pin(async move { this.read().await.next_task_id() })
}
2022-07-19 20:39:05 +08:00
fn add_task(&self, task: Task) -> BoxFuture<()> {
2022-06-29 20:51:53 +08:00
let this = self.clone();
Box::pin(async move {
2022-07-19 20:39:05 +08:00
this.write().await.add_task(task);
2022-06-29 20:51:53 +08:00
})
}
}