Skip to content
This repository was archived by the owner on Oct 30, 2019. It is now read-only.

Commit aea55f9

Browse files
taiki-eyoshuawuyts
authored andcommitted
Remove usage of async_closure (#69)
1 parent f98ce29 commit aea55f9

File tree

3 files changed

+33
-27
lines changed

3 files changed

+33
-27
lines changed

examples/guessing.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ async fn main() -> Result<(), failure::Error> {
6363

6464
let incoming = listener.incoming().map_err(|e| e.into());
6565
incoming
66-
.try_for_each_concurrent(None, async move |stream| {
67-
runtime::spawn(play(stream)).await?;
68-
Ok::<(), failure::Error>(())
66+
.try_for_each_concurrent(None, |stream| {
67+
async move {
68+
runtime::spawn(play(stream)).await?;
69+
Ok::<(), failure::Error>(())
70+
}
6971
})
7072
.await?;
7173
Ok(())

examples/tcp-echo.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@ async fn main() -> std::io::Result<()> {
1616
// accept connections and process them in parallel
1717
listener
1818
.incoming()
19-
.try_for_each_concurrent(None, async move |stream| {
20-
runtime::spawn(async move {
21-
println!("Accepting from: {}", stream.peer_addr()?);
19+
.try_for_each_concurrent(None, |stream| {
20+
async move {
21+
runtime::spawn(async move {
22+
println!("Accepting from: {}", stream.peer_addr()?);
2223

23-
let (reader, writer) = &mut stream.split();
24-
reader.copy_into(writer).await?;
25-
Ok::<(), std::io::Error>(())
26-
})
27-
.await
24+
let (reader, writer) = &mut stream.split();
25+
reader.copy_into(writer).await?;
26+
Ok::<(), std::io::Error>(())
27+
})
28+
.await
29+
}
2830
})
2931
.await?;
3032
Ok(())

examples/tcp-proxy.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,26 @@ async fn main() -> std::io::Result<()> {
1414
// accept connections and process them in parallel
1515
listener
1616
.incoming()
17-
.try_for_each_concurrent(None, async move |client| {
18-
runtime::spawn(async move {
19-
let server = TcpStream::connect("127.0.0.1:8080").await?;
20-
println!(
21-
"Proxying {} to {}",
22-
client.peer_addr()?,
23-
server.peer_addr()?
24-
);
17+
.try_for_each_concurrent(None, |client| {
18+
async move {
19+
runtime::spawn(async move {
20+
let server = TcpStream::connect("127.0.0.1:8080").await?;
21+
println!(
22+
"Proxying {} to {}",
23+
client.peer_addr()?,
24+
server.peer_addr()?
25+
);
2526

26-
let (cr, cw) = &mut client.split();
27-
let (sr, sw) = &mut server.split();
28-
let a = cr.copy_into(sw);
29-
let b = sr.copy_into(cw);
30-
try_join!(a, b)?;
27+
let (cr, cw) = &mut client.split();
28+
let (sr, sw) = &mut server.split();
29+
let a = cr.copy_into(sw);
30+
let b = sr.copy_into(cw);
31+
try_join!(a, b)?;
3132

32-
Ok::<(), std::io::Error>(())
33-
})
34-
.await
33+
Ok::<(), std::io::Error>(())
34+
})
35+
.await
36+
}
3537
})
3638
.await?;
3739
Ok(())

0 commit comments

Comments
 (0)