mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-03-21 04:01:01 +03:00
fix: Query online, remove loop retry (#9326)
Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
@@ -2057,18 +2057,18 @@ pub mod sessions {
|
||||
pub(super) mod async_tasks {
|
||||
use hbb_common::{
|
||||
bail,
|
||||
tokio::{
|
||||
self, select,
|
||||
sync::mpsc::{unbounded_channel, UnboundedSender},
|
||||
},
|
||||
tokio::{self, select},
|
||||
ResultType,
|
||||
};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
sync::{Arc, Mutex},
|
||||
sync::{
|
||||
mpsc::{sync_channel, SyncSender},
|
||||
Arc, Mutex,
|
||||
},
|
||||
};
|
||||
|
||||
type TxQueryOnlines = UnboundedSender<Vec<String>>;
|
||||
type TxQueryOnlines = SyncSender<Vec<String>>;
|
||||
lazy_static::lazy_static! {
|
||||
static ref TX_QUERY_ONLINES: Arc<Mutex<Option<TxQueryOnlines>>> = Default::default();
|
||||
}
|
||||
@@ -2085,20 +2085,18 @@ pub(super) mod async_tasks {
|
||||
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn start_flutter_async_runner_() {
|
||||
let (tx_onlines, mut rx_onlines) = unbounded_channel::<Vec<String>>();
|
||||
// Only one task is allowed to run at the same time.
|
||||
let (tx_onlines, rx_onlines) = sync_channel::<Vec<String>>(1);
|
||||
TX_QUERY_ONLINES.lock().unwrap().replace(tx_onlines);
|
||||
|
||||
loop {
|
||||
select! {
|
||||
ids = rx_onlines.recv() => {
|
||||
match ids {
|
||||
Some(_ids) => {
|
||||
crate::client::peer_online::query_online_states(_ids, handle_query_onlines).await
|
||||
}
|
||||
None => {
|
||||
break;
|
||||
}
|
||||
}
|
||||
match rx_onlines.recv() {
|
||||
Ok(ids) => {
|
||||
crate::client::peer_online::query_online_states(ids, handle_query_onlines).await
|
||||
}
|
||||
_ => {
|
||||
// unreachable!
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2106,7 +2104,8 @@ pub(super) mod async_tasks {
|
||||
|
||||
pub fn query_onlines(ids: Vec<String>) -> ResultType<()> {
|
||||
if let Some(tx) = TX_QUERY_ONLINES.lock().unwrap().as_ref() {
|
||||
let _ = tx.send(ids)?;
|
||||
// Ignore if the channel is full.
|
||||
let _ = tx.try_send(ids)?;
|
||||
} else {
|
||||
bail!("No tx_query_onlines");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user