aboutsummaryrefslogtreecommitdiffstats
path: root/examples/async-std.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/async-std.rs')
-rw-r--r--examples/async-std.rs15
1 files changed, 9 insertions, 6 deletions
diff --git a/examples/async-std.rs b/examples/async-std.rs
index 6bf9412..970841c 100644
--- a/examples/async-std.rs
+++ b/examples/async-std.rs
@@ -7,10 +7,13 @@ mod main {
use async_std::prelude::FutureExt as _;
pub async fn run(
- child: &pty_process::Child,
- ) -> std::result::Result<(), Box<dyn std::error::Error + '_>> {
+ child: &async_process::Child,
+ pty: &pty_process::Pty,
+ ) -> std::result::Result<(), Box<dyn std::error::Error + 'static>> {
let _raw = super::raw_guard::RawGuard::new();
+ let mut input_pty = pty;
+ let mut output_pty = pty;
let ex = async_executor::Executor::new();
let input = ex.spawn(async {
@@ -19,7 +22,7 @@ mod main {
loop {
match stdin.read(&mut buf).await {
Ok(bytes) => {
- child.pty().write_all(&buf[..bytes]).await.unwrap();
+ input_pty.write_all(&buf[..bytes]).await.unwrap();
}
Err(e) => {
eprintln!("stdin read failed: {:?}", e);
@@ -32,7 +35,7 @@ mod main {
let mut buf = [0_u8; 4096];
let mut stdout = async_std::io::stdout();
loop {
- match child.pty().read(&mut buf).await {
+ match output_pty.read(&mut buf).await {
Ok(bytes) => {
stdout.write_all(&buf[..bytes]).await.unwrap();
stdout.flush().await.unwrap();
@@ -64,9 +67,9 @@ fn main() {
pty.resize(pty_process::Size::new(24, 80)).unwrap();
let mut child = pty_process::Command::new("tac")
// .args(&["500"])
- .spawn(pty)
+ .spawn(&pty)
.unwrap();
- main::run(&child).await.unwrap();
+ main::run(&child, &pty).await.unwrap();
child.status().await.unwrap()
});
std::process::exit(