Ready to implement sync thread logic
This commit is contained in:
32
matrixgw_backend/src/matrix_connection/sync_thread.rs
Normal file
32
matrixgw_backend/src/matrix_connection/sync_thread.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
//! # Matrix sync thread
|
||||
//!
|
||||
//! This file contains the logic performed by the threads that synchronize with Matrix account.
|
||||
|
||||
use crate::broadcast_messages::BroadcastSender;
|
||||
use crate::matrix_connection::matrix_client::MatrixClient;
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct MatrixSyncTaskID(uuid::Uuid);
|
||||
|
||||
/// Start synchronization thread for a given user
|
||||
pub async fn start_sync_thread(
|
||||
client: MatrixClient,
|
||||
tx: BroadcastSender,
|
||||
) -> anyhow::Result<MatrixSyncTaskID> {
|
||||
let task_id = MatrixSyncTaskID(uuid::Uuid::new_v4());
|
||||
let task_id_clone = task_id.clone();
|
||||
|
||||
tokio::task::spawn(async move {
|
||||
sync_thread_task(task_id_clone, client, tx).await;
|
||||
});
|
||||
|
||||
Ok(task_id)
|
||||
}
|
||||
|
||||
/// Sync thread function for a single function
|
||||
async fn sync_thread_task(task_id: MatrixSyncTaskID, client: MatrixClient, _tx: BroadcastSender) {
|
||||
loop {
|
||||
println!("TODO : sync actions {task_id:?} {:?}", client.email);
|
||||
tokio::time::sleep(std::time::Duration::from_millis(1000)).await;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user