summaryrefslogtreecommitdiffstats
path: root/examples/connect.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/connect.rs')
-rw-r--r--examples/connect.rs13
1 files changed, 9 insertions, 4 deletions
diff --git a/examples/connect.rs b/examples/connect.rs
index f3ea6970..f44a5c1e 100644
--- a/examples/connect.rs
+++ b/examples/connect.rs
@@ -198,24 +198,29 @@ mod udp {
// All bytes from `stdin` will go to the `addr` specified in our
// argument list. Like with TCP this is spawned concurrently
- tokio::spawn(stdin.map(move |chunk| {
+ let forward_stdin = stdin.map(move |chunk| {
(chunk, addr)
}).forward(sink).then(|result| {
if let Err(e) = result {
panic!("failed to write to socket: {}", e)
}
Ok(())
- }));
+ });
// With UDP we could receive data from any source, so filter out
// anything coming from a different address
- Box::new(stream.filter_map(move |(chunk, src)| {
+ let receive = stream.filter_map(move |(chunk, src)| {
if src == addr {
Some(chunk.into())
} else {
None
}
- }))
+ });
+
+ Box::new(future::lazy(|| {
+ tokio::spawn(forward_stdin);
+ future::ok(receive)
+ }).flatten_stream())
}
}