Replies: 1 comment 1 reply
-
#[get("/hello")]
fn hello() -> TextStream![&'static str] {
let (send, recv) = rocket::tokio::sync::oneshot::channel::<()>();
let stream = TextStream! {
let _ = send; // capture the Sender
let mut interval = time::interval(Duration::from_secs(1));
loop {
println!("HELLO");
yield "hello";
interval.tick().await;
}
};
rocket::tokio::spawn(async move {
// Wait will Sender is alive
let _ = recv.await;
println!("User disconnected");
});
stream
} When the connection is closed, the |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello, I'm trying to detect when the event stream to a users client (browser) is closed.
After a short time rocket prints
Remote left: channel closed.
into the console, indicating that the browser is no longer listening to the event stream. I'm guessing that this is archived, because heartbeat is implemented for the stream.So my question is: How can I detect when a user stops listening to the event stream?
(I searched the docs but was unable to find a solution)
My code currently looks like this:
Beta Was this translation helpful? Give feedback.
All reactions