Skip to content

Commit

Permalink
wip: sketch spawning processes
Browse files Browse the repository at this point in the history
  • Loading branch information
cablehead committed Jun 7, 2024
1 parent 2144a0d commit 992c611
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,23 @@ pub async fn spawn(mut store: Store) -> Result<(), Box<dyn std::error::Error + S

loop {
tokio::select! {
Some(frame) = recver.recv() => {
eprintln!("FRAME: {:?}", &frame.topic);
if frame.topic == "ws.send" {
let content = store.cas_read(&frame.hash.unwrap()).await.unwrap();
let mut content = content;
content.push(b'\n');
eprintln!("CONTENT: {}", std::str::from_utf8(&content).unwrap());
if let Err(e) = stdin.write_all(&content).await {
eprintln!("Failed to write to stdin: {}", e);
frame = recver.recv() => {
match frame {
Some(frame) => {
eprintln!("FRAME: {:?}", &frame.topic);
if frame.topic == "ws.send" {
let content = store.cas_read(&frame.hash.unwrap()).await.unwrap();
let mut content = content;
content.push(b'\n');
eprintln!("CONTENT: {}", std::str::from_utf8(&content).unwrap());
if let Err(e) = stdin.write_all(&content).await {
eprintln!("Failed to write to stdin: {}", e);
break;
}
}
},
None => {
eprintln!("Receiver closed");
break;
}
}
Expand Down Expand Up @@ -82,5 +90,8 @@ pub async fn spawn(mut store: Store) -> Result<(), Box<dyn std::error::Error + S
let _ = child.wait().await;
eprintln!("child: outie");

let _ = stop_tx.send(true);
eprintln!("adios spawn");

Ok(())
}

0 comments on commit 992c611

Please sign in to comment.