fix(core): cli session keep session alive

This commit is contained in:
Kasper Juul Hermansen 2023-02-20 11:54:22 +01:00
parent 085a998bc6
commit 8dfecf976c
Signed by: kjuulh
GPG Key ID: 57B6E1465221F912

View File

@ -1,8 +1,7 @@
use std::{ use std::{
fs::canonicalize, fs::canonicalize,
io::{BufRead, BufReader},
path::PathBuf, path::PathBuf,
process::{Child, Stdio}, process::Stdio,
sync::Arc, sync::Arc,
}; };
@ -89,25 +88,20 @@ impl InnerCliSession {
let (sender, mut receiver) = tokio::sync::mpsc::channel(1); let (sender, mut receiver) = tokio::sync::mpsc::channel(1);
tokio::spawn(async move { tokio::spawn(async move {
let stdout_bufr = tokio::io::BufReader::new(stdout); let mut stdout_bufr = tokio::io::BufReader::new(stdout).lines();
for line in stdout_bufr.lines().next_line().await { while let Ok(Some(line)) = stdout_bufr.next_line().await {
let out = line.as_ref().unwrap(); if let Ok(conn) = serde_json::from_str::<ConnectParams>(&line) {
if let Ok(conn) = serde_json::from_str::<ConnectParams>(&out) {
sender.send(conn).await.unwrap(); sender.send(conn).await.unwrap();
} }
if let Some(line) = line {
println!("dagger: {}", line); println!("dagger: {}", line);
}
} }
}); });
tokio::spawn(async move { tokio::spawn(async move {
let stdout_bufr = tokio::io::BufReader::new(stderr); let mut stdout_bufr = tokio::io::BufReader::new(stderr).lines();
for line in stdout_bufr.lines().next_line().await { while let Ok(Some(line)) = stdout_bufr.next_line().await {
if let Some(line) = line { println!("dagger: {}", line);
println!("dagger: {}", line);
}
//panic!("could not start dagger session: {}", out)
} }
}); });