feat: enable dispatch event using single thread (#3828)

* refactor: lib dispatch

* chore: type def

* chore: type def

* fix: local set spawn

* chore: replace tokio spawn

* chore: update log

* chore: boxed event

* chore: tauri lock
This commit is contained in:
Nathan.fooo
2023-10-30 12:35:06 +08:00
committed by GitHub
parent 7f4e7e6aa0
commit e08a1a6974
67 changed files with 822 additions and 554 deletions

View File

@ -5,7 +5,7 @@ use collab_database::rows::RowId;
use tokio::sync::oneshot;
use flowy_error::{FlowyError, FlowyResult};
use lib_dispatch::prelude::{data_result_ok, AFPluginData, AFPluginState, DataResult};
use lib_dispatch::prelude::{af_spawn, data_result_ok, AFPluginData, AFPluginState, DataResult};
use lib_infra::util::timestamp;
use crate::entities::*;
@ -697,7 +697,7 @@ pub(crate) async fn update_group_handler(
let database_editor = manager.get_database_with_view_id(&view_id).await?;
let group_changeset = GroupChangeset::from(params);
let (tx, rx) = oneshot::channel();
tokio::spawn(async move {
af_spawn(async move {
let result = database_editor
.update_group(&view_id, vec![group_changeset].into())
.await;

View File

@ -20,6 +20,7 @@ use collab_integrate::{CollabPersistenceConfig, RocksCollabDB};
use flowy_database_deps::cloud::DatabaseCloudService;
use flowy_error::{internal_error, FlowyError, FlowyResult};
use flowy_task::TaskDispatcher;
use lib_dispatch::prelude::af_spawn;
use crate::entities::{
DatabaseDescriptionPB, DatabaseLayoutPB, DatabaseSnapshotPB, DidFetchRowPB,
@ -361,7 +362,7 @@ impl DatabaseManager {
/// Send notification to all clients that are listening to the given object.
fn subscribe_block_event(workspace_database: &WorkspaceDatabase) {
let mut block_event_rx = workspace_database.subscribe_block_event();
tokio::spawn(async move {
af_spawn(async move {
while let Ok(event) = block_event_rx.recv().await {
match event {
BlockEvent::DidFetchRow(row_details) => {

View File

@ -12,6 +12,7 @@ use tracing::{event, warn};
use flowy_error::{internal_error, ErrorCode, FlowyError, FlowyResult};
use flowy_task::TaskDispatcher;
use lib_dispatch::prelude::af_spawn;
use lib_infra::future::{to_fut, Fut, FutureResult};
use crate::entities::*;
@ -56,7 +57,7 @@ impl DatabaseEditor {
// Receive database sync state and send to frontend via the notification
let mut sync_state = database.lock().subscribe_sync_state();
let cloned_database_id = database_id.clone();
tokio::spawn(async move {
af_spawn(async move {
while let Some(sync_state) = sync_state.next().await {
send_notification(
&cloned_database_id,
@ -69,7 +70,7 @@ impl DatabaseEditor {
// Receive database snapshot state and send to frontend via the notification
let mut snapshot_state = database.lock().subscribe_snapshot_state();
tokio::spawn(async move {
af_spawn(async move {
while let Some(snapshot_state) = snapshot_state.next().await {
if let Some(new_snapshot_id) = snapshot_state.snapshot_id() {
tracing::debug!(

View File

@ -9,6 +9,7 @@ use collab_database::views::{DatabaseLayout, DatabaseView};
use tokio::sync::{broadcast, RwLock};
use flowy_error::{FlowyError, FlowyResult};
use lib_dispatch::prelude::af_spawn;
use crate::entities::{
CalendarEventPB, DatabaseLayoutMetaPB, DatabaseLayoutSettingPB, DeleteFilterParams,
@ -60,7 +61,7 @@ impl DatabaseViewEditor {
cell_cache: CellCache,
) -> FlowyResult<Self> {
let (notifier, _) = broadcast::channel(100);
tokio::spawn(DatabaseViewChangedReceiverRunner(Some(notifier.subscribe())).run());
af_spawn(DatabaseViewChangedReceiverRunner(Some(notifier.subscribe())).run());
// Group
let group_controller = Arc::new(RwLock::new(
new_group_controller(view_id.clone(), delegate.clone()).await?,
@ -237,7 +238,7 @@ impl DatabaseViewEditor {
let row_id = row_detail.row.id.clone();
let weak_filter_controller = Arc::downgrade(&self.filter_controller);
let weak_sort_controller = Arc::downgrade(&self.sort_controller);
tokio::spawn(async move {
af_spawn(async move {
if let Some(filter_controller) = weak_filter_controller.upgrade() {
filter_controller
.did_receive_row_changed(row_id.clone())
@ -645,7 +646,7 @@ impl DatabaseViewEditor {
let filter_type = UpdatedFilterType::new(Some(old), new);
let filter_changeset = FilterChangeset::from_update(filter_type);
let filter_controller = self.filter_controller.clone();
tokio::spawn(async move {
af_spawn(async move {
if let Some(notification) = filter_controller
.did_receive_changes(filter_changeset)
.await

View File

@ -12,6 +12,7 @@ use serde::Serialize;
use tracing::event;
use flowy_error::{FlowyError, FlowyResult};
use lib_dispatch::prelude::af_spawn;
use lib_infra::future::Fut;
use crate::entities::{GroupChangesPB, GroupPB, InsertedGroupPB};
@ -415,7 +416,7 @@ where
let configuration = (*self.setting).clone();
let writer = self.writer.clone();
let view_id = self.view_id.clone();
tokio::spawn(async move {
af_spawn(async move {
match writer.save_configuration(&view_id, configuration).await {
Ok(_) => {},
Err(e) => {