Rocket
Rocket copied to clipboard
Setting event type of `rocket::response::stream::Event::json` with `.event(...)` causes the SSE event to never arrive
Description
Setting event type of rocket::response::stream::Event::json
with .event(...)
causes the SSE event to never arrive
To Reproduce
Works:
#[get("/chat/events")]
pub async fn events(auth: Authentication, queue: &State<Sender<MessageEventData>>, mut end: Shutdown) -> EventStream![] {
let mut rx = queue.subscribe();
EventStream! {
loop {
let msg = select! {
msg = rx.recv() => match msg {
Ok(msg) => msg,
Err(RecvError::Closed) => break,
Err(RecvError::Lagged(_)) => continue,
},
_ = &mut end => break,
};
if msg.recv_user_id == auth.user_id {
yield Event::json(&msg);
//yield Event::json(&msg).event("new_message");
}
}
}
}
Does not:
#[get("/chat/events")]
pub async fn events(auth: Authentication, queue: &State<Sender<MessageEventData>>, mut end: Shutdown) -> EventStream![] {
let mut rx = queue.subscribe();
EventStream! {
loop {
let msg = select! {
msg = rx.recv() => match msg {
Ok(msg) => msg,
Err(RecvError::Closed) => break,
Err(RecvError::Lagged(_)) => continue,
},
_ = &mut end => break,
};
if msg.recv_user_id == auth.user_id {
//yield Event::json(&msg);
yield Event::json(&msg).event("new_message");
}
}
}
}
Expected Behavior
SSE event should be sent/received properly
Environment:
- OS Distribution and Kernel: Win10
- Rocket Version: 0.5.0-rc.2
Additional Context