Skip to content

Is it possible to stream html? #2696

Closed Answered by rubiktubik
rubiktubik asked this question in Questions
Discussion options

You must be logged in to vote

With your help I have found an answer which works:

#[get("/events")]
fn events() -> EventStream![] {
    EventStream! {
        let mut count = 0;
        let mut interval = time::interval(Duration::from_secs(1));
        loop {
        let output = format!(
        r#"<progress max="{}" value="{}">{}%</progress>"#,
        100, count, count
    );
            yield Event::data(output.clone()).id("message");
            interval.tick().await;
            count += 1;
            if count == 100 {
                break;
            }
        }
    }
}

And the corresponding html:

  <div hx-ext="sse" sse-connect="/events" sse-swap="message">
    Contents of this box will be updated in real ti…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@rubiktubik
Comment options

@SergioBenitez
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by rubiktubik
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants