* improve documentation for the fullstack server context * Add a section about axum integration to the crate root docs * make serve_dioxus_application accept the cfg builder directly * remove unused server_fn module * improve fullstack config docs * improve documentation for the server function macro * fix axum router extension link * Fix doc tests * Fix launch builder * Simplify the launch builder * don't re-export launch in the prelude * refactor fullstack launch * Fix fullstack launch builder * Update static generation with the new builder api * fix some formatting/overly broad launch replacements * fix custom menu example * fix fullstack/static generation examples * Fix static generation launch * A few small formatting fixes * Fix a few doc tests * implement LaunchConfig for serve configs * fix fullstack launch with separate web and server launch methods * fix check with all features * dont expose inner core module * clippy and check * fix readme --------- Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
42 lines
1.1 KiB
Rust
42 lines
1.1 KiB
Rust
use dioxus::prelude::*;
|
|
use futures::StreamExt;
|
|
use server_fn::codec::{StreamingText, TextStream};
|
|
|
|
fn app() -> Element {
|
|
let mut response = use_signal(String::new);
|
|
|
|
rsx! {
|
|
button {
|
|
onclick: move |_| async move {
|
|
response.write().clear();
|
|
if let Ok(stream) = test_stream().await {
|
|
response.write().push_str("Stream started\n");
|
|
let mut stream = stream.into_inner();
|
|
while let Some(Ok(text)) = stream.next().await {
|
|
response.write().push_str(&text);
|
|
}
|
|
}
|
|
},
|
|
"Start stream"
|
|
}
|
|
"{response}"
|
|
}
|
|
}
|
|
|
|
#[server(output = StreamingText)]
|
|
pub async fn test_stream() -> Result<TextStream, ServerFnError> {
|
|
let (tx, rx) = futures::channel::mpsc::unbounded();
|
|
tokio::spawn(async move {
|
|
loop {
|
|
tokio::time::sleep(tokio::time::Duration::from_millis(500)).await;
|
|
let _ = tx.unbounded_send(Ok("Hello, world!".to_string()));
|
|
}
|
|
});
|
|
|
|
Ok(TextStream::new(rx))
|
|
}
|
|
|
|
fn main() {
|
|
dioxus::launch(app)
|
|
}
|