48 lines
1.4 KiB
Rust
48 lines
1.4 KiB
Rust
use crate::group::cmd::{GroupCommand, GroupCommandSender};
|
|
use collab::entity::EncodedCollab;
|
|
use dashmap::DashMap;
|
|
use std::sync::Arc;
|
|
use tracing::error;
|
|
|
|
pub type CLCommandSender = tokio::sync::mpsc::Sender<CollaborationCommand>;
|
|
pub type CLCommandReceiver = tokio::sync::mpsc::Receiver<CollaborationCommand>;
|
|
|
|
pub type EncodeCollabSender = tokio::sync::oneshot::Sender<Option<EncodedCollab>>;
|
|
pub enum CollaborationCommand {
|
|
GetEncodeCollab {
|
|
object_id: String,
|
|
ret: EncodeCollabSender,
|
|
},
|
|
}
|
|
|
|
pub(crate) fn spawn_collaboration_command(
|
|
mut command_recv: CLCommandReceiver,
|
|
group_sender_by_object_id: &Arc<DashMap<String, GroupCommandSender>>,
|
|
) {
|
|
let group_sender_by_object_id = group_sender_by_object_id.clone();
|
|
tokio::spawn(async move {
|
|
while let Some(cmd) = command_recv.recv().await {
|
|
match cmd {
|
|
CollaborationCommand::GetEncodeCollab { object_id, ret } => {
|
|
match group_sender_by_object_id.get(&object_id) {
|
|
Some(sender) => {
|
|
if let Err(err) = sender
|
|
.send(GroupCommand::EncodeCollab {
|
|
object_id: object_id.clone(),
|
|
ret,
|
|
})
|
|
.await
|
|
{
|
|
error!("Send group command error: {}", err);
|
|
}
|
|
},
|
|
None => {
|
|
let _ = ret.send(None);
|
|
},
|
|
}
|
|
},
|
|
}
|
|
}
|
|
});
|
|
}
|