chunk qui marche

This commit is contained in:
hubert 2021-07-09 13:27:28 +02:00
parent 81c9669e17
commit 02245bf01c
2 changed files with 21 additions and 0 deletions

View File

@ -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"]}

View File

@ -100,6 +100,24 @@ struct GitWebQ {
}
#[get("/chunk")]
async fn chunk() -> HttpResponse {
let (tx, rx) = actix_utils::mpsc::channel::<Result<Bytes, Error>>();
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<GitWebQ>) -> 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")