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-06-29 20:51:53 +08:00
|
|
|
use crate::services::tasks::{GridTaskHandler, Task, TaskContent, TaskHandlerId, 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>;
|
|
|
|
fn register_task(&self, task: Task) -> BoxFuture<()>;
|
|
|
|
}
|
|
|
|
|
2022-06-29 16:55:52 +08:00
|
|
|
impl GridTaskHandler for GridRevisionEditor {
|
|
|
|
fn handler_id(&self) -> &TaskHandlerId {
|
2022-06-29 13:44:15 +08:00
|
|
|
&self.grid_id
|
|
|
|
}
|
|
|
|
|
|
|
|
fn process_task(&self, task: Task) -> BoxResultFuture<(), FlowyError> {
|
|
|
|
Box::pin(async move {
|
2022-06-30 23:00:03 +08:00
|
|
|
match task.content {
|
|
|
|
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() })
|
|
|
|
}
|
|
|
|
|
|
|
|
fn register_task(&self, task: Task) -> BoxFuture<()> {
|
|
|
|
let this = self.clone();
|
|
|
|
Box::pin(async move {
|
|
|
|
this.write().await.register_task(task);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|