Bläddra i källkod

优化后的代码再试验一下稳定性。

skyfffire 1 år sedan
förälder
incheckning
7778ae1ffa
1 ändrade filer med 14 tillägg och 12 borttagningar
  1. 14 12
      exchanges/tests/binance_swap_test.rs

+ 14 - 12
exchanges/tests/binance_swap_test.rs

@@ -16,7 +16,7 @@ const SECRET_KEY: &str = "";
 
 
 //ws-订阅公共频道信息
-#[tokio::test(flavor = "multi_thread")]
+#[tokio::test(flavor = "multi_thread", worker_threads = 8)]
 async fn ws_custom_subscribe() {
     global::log_utils::init_log_with_trace();
 
@@ -46,19 +46,21 @@ async fn ws_custom_subscribe() {
         trace!("线程-数据读取-开启");
         loop {
             if let Some(data) = read_rx.next().await {
-                let mut trace_stack = TraceStack::default();
-                trace_stack.on_after_network(data.time);
-                trace_stack.on_before_unlock_quant();
-
-                if data.time != 0 {
-                    info!("bian>{}", trace_stack.to_string());
+                tokio::spawn(async move {
+                    let mut trace_stack = TraceStack::default();
+                    trace_stack.on_before_unlock_quant();
+                    trace_stack.on_after_network(data.time);
+
+                    if data.time != 0 {
+                        info!("bian>{}", trace_stack.to_string());
+                    }
+                });
+
+                // 从通道中接收并丢弃所有的消息,直到通道为空
+                while let Ok(Some(_)) = read_rx.try_next() {
+                    // 消息被忽略
                 }
             }
-
-            // 从通道中接收并丢弃所有的消息,直到通道为空
-            while let Ok(Some(_)) = read_rx.try_next() {
-                // 消息被忽略
-            }
         }
         // trace!("线程-数据读取-结束");
     });