Skip to content

Instantly share code, notes, and snippets.

@yoshuawuyts
Created December 25, 2018 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoshuawuyts/f10ed1bbaa9d1cb0ca12061c1fcf4a0f to your computer and use it in GitHub Desktop.
Save yoshuawuyts/f10ed1bbaa9d1cb0ca12061c1fcf4a0f to your computer and use it in GitHub Desktop.
fn main() -> io::Result<()> {
executor::block_on(async {
let listener = TcpListener::bind(&"127.0.0.1:7878".parse().unwrap())?;
let mut incoming = listener.incoming();
while let Some(stream) = await!(incoming.next()) {
let stream = stream?;
let addr = stream.peer_addr()?;
juliex::spawn(async move {
let (mut reader, mut writer) = stream.split();
await!(reader.copy_into(&mut writer)).unwrap(); // Just unwrap?
});
}
Ok(())
})
}
async fn main() -> io::Result<()> {
let listener = TcpListener::bind(&"127.0.0.1:7878".parse()?)?;
#[parallel]
for await stream? in listener.incoming() {
let (mut reader, mut writer) = stream.split();
await reader.copy_into(&mut writer)?;
}
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment