vnj/src/http/novels/pull_next.rs
2024-11-17 18:34:33 +03:00

24 lines
530 B
Rust

use std::time::Duration;
use crate::{
result::ApiResult,
state::{Router, State},
};
use axum::routing::get;
use tokio::time;
async fn pull_next(state: State) -> ApiResult<Option<String>> {
let rx = state.app.write().subs.subscribe();
let Ok(Ok(r)) = time::timeout(Duration::from_secs(12 * 60 * 60), rx).await else {
tracing::debug!("timed out for subscription");
return Ok(None.into());
};
Ok(Some(r).into())
}
pub fn make() -> Router {
Router::new().route("/", get(pull_next))
}