Skip to content

Commit 3a877e3

Browse files
committed
Event stream API add heathbeat
1 parent 20c55a4 commit 3a877e3

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/epsilon/api/routes.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
use std::sync::Arc;
22

3-
use rocket::{Shutdown, State};
43
use rocket::response::stream::{Event, EventStream};
4+
use rocket::{Shutdown, State};
55
use serde_json::json;
6+
use std::time::Duration;
67
use tokio::select;
78
use tokio::sync::broadcast::error::RecvError;
89

9-
use crate::Context;
1010
use crate::epsilon::api::common::epsilon_events::EpsilonEvent;
11+
use crate::Context;
1112

1213
#[rocket::get("/ping")]
1314
pub async fn ping() -> &'static str {
@@ -20,7 +21,7 @@ pub async fn events(context: &State<Arc<Context>>, mut end: Shutdown) -> EventSt
2021

2122
let mut rx = epsilon_api.subscribe();
2223

23-
EventStream! {
24+
let stream = EventStream! {
2425
loop {
2526
let event: EpsilonEvent = select! {
2627
event = rx.recv() => match event {
@@ -44,5 +45,7 @@ pub async fn events(context: &State<Arc<Context>>, mut end: Shutdown) -> EventSt
4445
}
4546
}
4647
}
47-
}
48+
};
49+
50+
stream.heartbeat(Duration::from_secs(5))
4851
}

0 commit comments

Comments
 (0)