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-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-29 20:51:53 +08:00
pub trait GridServiceTaskScheduler: Send + Sync + 'static {
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-29 16:55:52 +08:00
match &task.content {
2022-06-29 13:44:15 +08:00
TaskContent::Snapshot { .. } => {}
2022-06-29 20:51:53 +08:00
TaskContent::Filter { .. } => self.filter_service.process_task(task).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);
})
}
}