소스 검색

设置等待时间,防止执行过快

JiahengHe 8 달 전
부모
커밋
5bda2614a1
1개의 변경된 파일8개의 추가작업 그리고 5개의 파일을 삭제
  1. 8 5
      src/core_libs.rs

+ 8 - 5
src/core_libs.rs

@@ -144,14 +144,17 @@ pub async fn init(params: Params,
             // 计算需要等待的时间
             let wait_duration = next_hour - now;
             let wait_secs = wait_duration.num_seconds() as u64;
-
-
-            // 等待到下一个整点
-            sleep_until(Instant::now() + std::time::Duration::from_secs(wait_secs)).await;
-
+            
+            if wait_secs > 0 {
+                sleep_until(Instant::now() + Duration::from_secs(wait_secs)).await;
+            }
+            
             // 更新近7天的交易量统计
             let mut core = trade_volume_core_arc.lock().await;
             core.update_trade_volume().await;
+
+            // 等待一分钟以避免过快地循环
+            sleep_until(Instant::now() + Duration::from_secs(60)).await;
         }
     });