From 8bcbe78dbee1b8cd838034774a2c29861d677fc2 Mon Sep 17 00:00:00 2001 From: Juan Alvarez Date: Tue, 3 Dec 2019 18:07:09 -0600 Subject: remove io workarounds from example (#1891) This PR removes no longer needed io workarounds from connect example. --- examples/connect.rs | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) (limited to 'examples') diff --git a/examples/connect.rs b/examples/connect.rs index 34b3488d..cdd18e19 100644 --- a/examples/connect.rs +++ b/examples/connect.rs @@ -17,27 +17,14 @@ #![warn(rust_2018_idioms)] use tokio::io; -use tokio::sync::{mpsc, oneshot}; use tokio_util::codec::{FramedRead, FramedWrite}; -use futures::{Stream, StreamExt}; use std::env; use std::error::Error; use std::net::SocketAddr; #[tokio::main] async fn main() -> Result<(), Box> { - let (tx, rx) = oneshot::channel(); - tokio::spawn(async move { - run().await.unwrap(); - tx.send(()).unwrap(); - }); - - rx.await.map_err(Into::into) -} - -// Currently, we need to spawn the initial future due to https://github.com/tokio-rs/tokio/issues/1356 -async fn run() -> Result<(), Box> { // Determine if we're going to run in TCP or UDP mode let mut args = env::args().skip(1).collect::>(); let tcp = match args.iter().position(|a| a == "--udp") { @@ -55,7 +42,7 @@ async fn run() -> Result<(), Box> { }; let addr = addr.parse::()?; - let stdin = stdin(); + let stdin = FramedRead::new(io::stdin(), codec::Bytes); let stdout = FramedWrite::new(io::stdout(), codec::Bytes); if tcp { @@ -67,21 +54,6 @@ async fn run() -> Result<(), Box> { Ok(()) } -// Temporary work around for stdin blocking the stream -fn stdin() -> impl Stream, io::Error>> + Unpin { - let mut stdin = FramedRead::new(io::stdin(), codec::Bytes); - - let (tx, rx) = mpsc::unbounded_channel(); - - tokio::spawn(async move { - while let Some(res) = stdin.next().await { - let _ = tx.send(res); - } - }); - - rx -} - mod tcp { use super::codec; use futures::{future, Sink, SinkExt, Stream, StreamExt}; -- cgit v1.2.3