summaryrefslogtreecommitdiffstats
path: root/examples/echo-udp.rs
diff options
context:
space:
mode:
authorCarl Lerche <me@carllerche.com>2018-03-06 09:59:04 -0800
committerGitHub <noreply@github.com>2018-03-06 09:59:04 -0800
commitf1cb12e14fb047f3f86c852c253962c60ce471e8 (patch)
tree59aab45a28961b00f7c71c5eb083c6242b51ff01 /examples/echo-udp.rs
parent56c579787260abcb9786aa22cfca1ee4b7c3b5ba (diff)
Update examples to track latest Tokio changes (#180)
The exampes included in the repository have lagged behind the changes made. Specifically, they do not use the new runtime construct. This patch updates examples to use the latest features of Tokio.
Diffstat (limited to 'examples/echo-udp.rs')
-rw-r--r--examples/echo-udp.rs19
1 files changed, 13 insertions, 6 deletions
diff --git a/examples/echo-udp.rs b/examples/echo-udp.rs
index 18f2d393..e25f0936 100644
--- a/examples/echo-udp.rs
+++ b/examples/echo-udp.rs
@@ -10,15 +10,16 @@
//!
//! Each line you type in to the `nc` terminal should be echo'd back to you!
+#![deny(warnings)]
+
#[macro_use]
extern crate futures;
extern crate tokio;
-extern crate tokio_io;
use std::{env, io};
use std::net::SocketAddr;
-use futures::{Future, Poll};
+use tokio::prelude::*;
use tokio::net::UdpSocket;
struct Server {
@@ -56,11 +57,17 @@ fn main() {
let socket = UdpSocket::bind(&addr).unwrap();
println!("Listening on: {}", socket.local_addr().unwrap());
- // Next we'll create a future to spawn (the one we defined above) and then
- // we'll block our current thread waiting on the result of the future
- Server {
+ let server = Server {
socket: socket,
buf: vec![0; 1024],
to_send: None,
- }.wait().unwrap();
+ };
+
+ // This starts the server task.
+ //
+ // `map_err` handles the error by logging it and maps the future to a type
+ // that can be spawned.
+ //
+ // `tokio::run` spanws the task on the Tokio runtime and starts running.
+ tokio::run(server.map_err(|e| println!("server error = {:?}", e)));
}