Refact. Replace all tokio::time::interval() (#7173)

* Refact. Replace all `tokio::time::interval()`

Signed-off-by: fufesou <shuanglongchen@yeah.net>

* Refact Better min_interval for `ThrottledInterval`.

Signed-off-by: fufesou <shuanglongchen@yeah.net>

---------

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou
2024-02-18 21:18:00 +08:00
committed by GitHub
parent 5fdcc748e1
commit 8c108065eb
9 changed files with 153 additions and 39 deletions

View File

@@ -1038,9 +1038,7 @@ async fn check_connect_status_(reconnect: bool, rx: mpsc::UnboundedReceiver<ipc:
loop {
if let Ok(mut c) = ipc::connect(1000, "").await {
const TIMER_OUT: time::Duration = time::Duration::from_secs(1);
let mut timer = time::interval(TIMER_OUT);
let mut last_timer = time::Instant::now() - TIMER_OUT * 2;
let mut timer = crate::rustdesk_interval(time::interval(time::Duration::from_secs(1)));
loop {
tokio::select! {
res = c.next() => {
@@ -1108,11 +1106,6 @@ async fn check_connect_status_(reconnect: bool, rx: mpsc::UnboundedReceiver<ipc:
allow_err!(c.send(&data).await);
}
_ = timer.tick() => {
if last_timer.elapsed() < TIMER_OUT {
continue;
}
last_timer = time::Instant::now();
c.send(&ipc::Data::OnlineStatus(None)).await.ok();
c.send(&ipc::Data::Options(None)).await.ok();
c.send(&ipc::Data::Config(("id".to_owned(), None))).await.ok();