From 02245bf01c992e3bb74496ab4daec1cf50622669 Mon Sep 17 00:00:00 2001 From: hubert Date: Fri, 9 Jul 2021 13:27:28 +0200 Subject: [PATCH] chunk qui marche --- Cargo.toml | 2 ++ src/main.rs | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 095a461..42971e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,8 +11,10 @@ actix-web = "3.3.2" actix-session = "0.4.1" actix-web-httpauth = "0.5.1" actix-files = "0.5.0" +actix-utils = "2.0.0" askama = "0.10.5" askama_actix = "0.11.1" env_logger = "0.8.4" serde = "1.0.126" futures = "0.3.15" +tokio = {version = "0.2.25", features = ["time"]} diff --git a/src/main.rs b/src/main.rs index 8202621..f8d50d1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -100,6 +100,24 @@ struct GitWebQ { } +#[get("/chunk")] +async fn chunk() -> HttpResponse { + let (tx, rx) = actix_utils::mpsc::channel::>(); + actix_web::rt::spawn(async move { + if tx.send(Ok(Bytes::from_static(b"trying to echo"))).is_err() { + return; + }; + + while true { + tokio::time::delay_for(std::time::Duration::from_secs(1)).await; + println!("send message"); + tx.send(Ok(Bytes::from_static(b"coucou"))); + } + }); + + HttpResponse::Ok().streaming(rx) +} + #[get("/git/{owner}/{repo}.git")] async fn git_main(web::Path((owner, reponame)): web::Path<(String, String)>, web::Query(GitWebQ{commit : commitnameopt, path : pathopt}) : web::Query) -> impl Responder { let commitname = match commitnameopt { @@ -292,6 +310,7 @@ async fn main() -> std::io::Result<()> { .service(askama) .service(git_main) .service(hello_session) + .service(chunk) //.service(git_proto) // .service( // web::scope("/auth")