This commit is contained in:
Tony Rewin 2023-10-02 15:35:16 +03:00
parent 65821f561d
commit 152a8da157

View File

@ -96,7 +96,7 @@ async fn sse_handler(
#[actix_web::main] #[actix_web::main]
async fn main() -> std::io::Result<()> { async fn main() -> std::io::Result<()> {
let (tx, rx) = broadcast::channel(100); let (tx, mut rx) = broadcast::channel(100);
let redis_url = env::var("REDIS_URL").unwrap(); let redis_url = env::var("REDIS_URL").unwrap();
let client = redis::Client::open(redis_url).unwrap(); let client = redis::Client::open(redis_url).unwrap();
let _handle = tokio::spawn(async move { let _handle = tokio::spawn(async move {
@ -114,8 +114,9 @@ async fn main() -> std::io::Result<()> {
}); });
HttpServer::new(move || { HttpServer::new(move || {
let rx = tx.subscribe();
App::new() App::new()
.app_data(web::Data::new(rx.subscribe())) .app_data(web::Data::new(rx))
.app_data(web::Data::new(client.clone())) .app_data(web::Data::new(client.clone()))
.route("/aware/{token}", web::get().to(sse_handler)) .route("/aware/{token}", web::get().to(sse_handler))
}) })