html terminal
Diffstat (limited to 'src/process.rs')
-rw-r--r--src/process.rs21
1 files changed, 5 insertions, 16 deletions
diff --git a/src/process.rs b/src/process.rs
index 1a5c9fb..bfa284e 100644
--- a/src/process.rs
+++ b/src/process.rs
@@ -1,9 +1,9 @@
use std::time::Duration;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::TcpStream;
-use tokio::sync::broadcast;
-use tokio::sync::broadcast::error::TryRecvError;
+use tokio::sync::broadcast::{self, error::TryRecvError};
use tokio::task::JoinHandle;
+use tokio::time::sleep;
pub struct Process {
inner: TcpStream,
@@ -13,7 +13,6 @@ pub struct Process {
impl Process {
/// spawns the server
- #[must_use]
pub async fn spawn() -> anyhow::Result<Self> {
let stream = TcpStream::connect("localhost:6859").await?;
Ok(Self {
@@ -41,7 +40,7 @@ impl Process {
let mut stdout = [0; 4096];
loop {
if output.receiver_count() == 0 {
- async_std::task::sleep(Duration::from_millis(500)).await;
+ sleep(Duration::from_millis(500)).await;
continue;
}
match input.try_recv() {
@@ -54,16 +53,6 @@ impl Process {
input!("{s}");
s += "\n";
self.inner.write_all(s.as_bytes()).await.unwrap();
- // let mut last = 250;
- // while let Err(e) = self.inner.write_all(s.as_bytes()).await {
- // last *= last;
- // if e.kind() == std::io::ErrorKind::BrokenPipe {
- // println!("failed write, waiting {last}ms to retry.");
- // async_std::task::sleep(Duration::from_millis(last)).await;
- // continue;
- // }
- // panic!("{e:?}");
- // }
self.inner.flush().await.unwrap();
}
}
@@ -71,7 +60,7 @@ impl Process {
let string = {
let n = tokio::select! {
n = {self.inner.read(&mut stdout)} => n.unwrap(),
- _ = async_std::task::sleep(Duration::from_millis(500)) => continue,
+ _ = sleep(Duration::from_millis(500)) => continue,
};
String::from_utf8_lossy(&stdout[..n]).into_owned()
};
@@ -82,7 +71,7 @@ impl Process {
String::from_utf8_lossy(&strip_ansi_escapes::strip(&string).unwrap())
.into_owned();
output.send(stripped).unwrap();
- async_std::task::sleep(Duration::from_millis(500)).await;
+ sleep(Duration::from_millis(500)).await;
}
})
}