浏览代码

Fix the test_stream function running after the stream is closed (#3396)

Evan Almloff 5 月之前
父节点
当前提交
5ea0867a34
共有 1 个文件被更改,包括 4 次插入1 次删除
  1. 4 1
      examples/fullstack-streaming/src/main.rs

+ 4 - 1
examples/fullstack-streaming/src/main.rs

@@ -30,7 +30,10 @@ pub async fn test_stream() -> Result<TextStream, ServerFnError> {
         loop {
             tokio::time::sleep(tokio::time::Duration::from_millis(500)).await;
             dioxus::logger::tracing::info!("Sending new chunk!");
-            let _ = tx.unbounded_send(Ok("Hello, world!".to_string()));
+            if tx.unbounded_send(Ok("Hello, world!".to_string())).is_err() {
+                // If the channel is closed, stop sending chunks
+                break;
+            }
         }
     });