Browse Source

新架构测试通过。

skyfffire 1 năm trước cách đây
mục cha
commit
7c218cee94
2 tập tin đã thay đổi với 54 bổ sung1 xóa
  1. 1 1
      Cargo.toml
  2. 53 0
      tests/framework_3_0_test.rs

+ 1 - 1
Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "as-rust"
-version = "1.5.5"
+version = "3.0.0"
 edition = "2021"
 
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

+ 53 - 0
tests/framework_3_0_test.rs

@@ -0,0 +1,53 @@
+use std::future::Future;
+use std::time::Duration;
+use exchanges::response_base::ResponseData;
+use std::sync::Arc;
+use tokio::sync::Mutex;
+use tracing::info;
+use global::log_utils::init_log_with_info;
+
+
+struct Node {
+    pub count: u128
+}
+
+#[tokio::test]
+async fn main() {
+    init_log_with_info();
+
+    let node = Arc::new(Mutex::new(Node { count: 0 }));
+
+    generator(handle, node).await;
+}
+
+// 消息创造者
+async fn generator<F, Fut>(handle_function: F, node: Arc<Mutex<Node>>)
+where
+    F: Fn(Arc<Mutex<Node>>, ResponseData) -> Fut,
+    Fut: Future<Output = ()> + Send + 'static, // 确保 Fut 是一个 Future,且输出类型为 ()
+{
+    let mut data = ResponseData::new("aaa".to_string(),
+                                 "code".to_string(),
+                                 "msg".to_string(),
+                                 "data".to_string());
+    loop {
+        let mut s_data = data.clone();
+        s_data.time = chrono::Utc::now().timestamp_micros();
+
+        handle_function(node.clone(), s_data).await;
+
+        tokio::time::sleep(Duration::from_micros(100)).await;
+    }
+}
+
+// 消息处理者
+async fn handle(node: Arc<Mutex<Node>>, data: ResponseData) {
+    let mut node = node.lock().await;
+    // 实现您的处理逝剧
+    // 例如,增加计数:
+    node.count += 1;
+    let delay = chrono::Utc::now().timestamp_micros() - data.time;
+    // 处理响应数据
+    info!("Handled data: {}, count is: {}, delay is: {}.", data.data, node.count, delay);
+}
+