Rocket icon indicating copy to clipboard operation
Rocket copied to clipboard

Setting event type of `rocket::response::stream::Event::json` with `.event(...)` causes the SSE event to never arrive

Open griffi-gh opened this issue 1 year ago • 0 comments

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

griffi-gh avatar Sep 16 '22 17:09 griffi-gh