[fix](trx-frontend-http): keep spectrum SSE alive on idle ticks
Signed-off-by: Stan Grams <sjg@haxx.space> Co-authored-by: OpenAI Codex <codex@openai.com>
This commit is contained in:
@@ -299,9 +299,9 @@ pub async fn spectrum(
|
|||||||
context: web::Data<Arc<FrontendRuntimeContext>>,
|
context: web::Data<Arc<FrontendRuntimeContext>>,
|
||||||
) -> Result<HttpResponse, Error> {
|
) -> Result<HttpResponse, Error> {
|
||||||
let context_updates = context.get_ref().clone();
|
let context_updates = context.get_ref().clone();
|
||||||
let updates = IntervalStream::new(time::interval(Duration::from_millis(200))).scan(
|
let mut last_json: Option<String> = None;
|
||||||
None::<String>,
|
let updates =
|
||||||
move |last_json, _| {
|
IntervalStream::new(time::interval(Duration::from_millis(200))).filter_map(move |_| {
|
||||||
let context = context_updates.clone();
|
let context = context_updates.clone();
|
||||||
std::future::ready({
|
std::future::ready({
|
||||||
let next_json = context
|
let next_json = context
|
||||||
@@ -313,11 +313,11 @@ pub async fn spectrum(
|
|||||||
let payload = match (last_json.as_ref(), next_json) {
|
let payload = match (last_json.as_ref(), next_json) {
|
||||||
(Some(prev), Some(next)) if prev == &next => None,
|
(Some(prev), Some(next)) if prev == &next => None,
|
||||||
(_, Some(next)) => {
|
(_, Some(next)) => {
|
||||||
*last_json = Some(next.clone());
|
last_json = Some(next.clone());
|
||||||
Some(next)
|
Some(next)
|
||||||
}
|
}
|
||||||
(Some(_), None) => {
|
(Some(_), None) => {
|
||||||
*last_json = None;
|
last_json = None;
|
||||||
Some("null".to_string())
|
Some("null".to_string())
|
||||||
}
|
}
|
||||||
(None, None) => None,
|
(None, None) => None,
|
||||||
@@ -325,8 +325,7 @@ pub async fn spectrum(
|
|||||||
|
|
||||||
payload.map(|json| Ok::<Bytes, Error>(Bytes::from(format!("data: {json}\n\n"))))
|
payload.map(|json| Ok::<Bytes, Error>(Bytes::from(format!("data: {json}\n\n"))))
|
||||||
})
|
})
|
||||||
},
|
});
|
||||||
);
|
|
||||||
|
|
||||||
let pings = IntervalStream::new(time::interval(Duration::from_secs(15)))
|
let pings = IntervalStream::new(time::interval(Duration::from_secs(15)))
|
||||||
.map(|_| Ok::<Bytes, Error>(Bytes::from(": ping\n\n")));
|
.map(|_| Ok::<Bytes, Error>(Bytes::from(": ping\n\n")));
|
||||||
|
|||||||
Reference in New Issue
Block a user