mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-26 00:00:16 +02:00
Swap Handle/Pinned
* Handle -> Remote * Pinned -> Handle All APIs now take a `&Handle` by default and in general can return an immediate `io::Result` instead of an `IoFuture`. This reflects how most usage will likely be done through handles rather than remotes, and also all previous functionality can be recovered with a `oneshot` plus `Remote::spawn`. Closes #15
This commit is contained in:
+20
-25
@@ -58,34 +58,32 @@
|
||||
//!
|
||||
//! // Create the event loop that will drive this server
|
||||
//! let mut l = Core::new().unwrap();
|
||||
//! let pin = l.pin();
|
||||
//! let handle = l.handle();
|
||||
//!
|
||||
//! // Create a TCP listener which will listen for incoming connections
|
||||
//! let server = TcpListener::bind(&addr, pin.handle());
|
||||
//! let socket = TcpListener::bind(&addr, &handle).unwrap();
|
||||
//!
|
||||
//! let done = server.and_then(|socket| {
|
||||
//! // Once we've got the TCP listener, inform that we have it
|
||||
//! println!("Listening on: {}", addr);
|
||||
//! // Once we've got the TCP listener, inform that we have it
|
||||
//! println!("Listening on: {}", addr);
|
||||
//!
|
||||
//! // Pull out the stream of incoming connections and then for each new
|
||||
//! // one spin up a new task copying data.
|
||||
//! //
|
||||
//! // We use the `io::copy` future to copy all data from the
|
||||
//! // reading half onto the writing half.
|
||||
//! socket.incoming().for_each(|(socket, addr)| {
|
||||
//! let pair = futures::lazy(|| Ok(socket.split()));
|
||||
//! let amt = pair.and_then(|(reader, writer)| copy(reader, writer));
|
||||
//!
|
||||
//! // Once all that is done we print out how much we wrote, and then
|
||||
//! // critically we *spawn* this future which allows it to run
|
||||
//! // concurrently with other connections.
|
||||
//! pin.spawn(amt.then(move |result| {
|
||||
//! println!("wrote {:?} bytes to {}", result, addr);
|
||||
//! Ok(())
|
||||
//! }));
|
||||
//! // Pull out the stream of incoming connections and then for each new
|
||||
//! // one spin up a new task copying data.
|
||||
//! //
|
||||
//! // We use the `io::copy` future to copy all data from the
|
||||
//! // reading half onto the writing half.
|
||||
//! let done = socket.incoming().for_each(|(socket, addr)| {
|
||||
//! let pair = futures::lazy(|| Ok(socket.split()));
|
||||
//! let amt = pair.and_then(|(reader, writer)| copy(reader, writer));
|
||||
//!
|
||||
//! // Once all that is done we print out how much we wrote, and then
|
||||
//! // critically we *spawn* this future which allows it to run
|
||||
//! // concurrently with other connections.
|
||||
//! handle.spawn(amt.then(move |result| {
|
||||
//! println!("wrote {:?} bytes to {}", result, addr);
|
||||
//! Ok(())
|
||||
//! })
|
||||
//! }));
|
||||
//!
|
||||
//! Ok(())
|
||||
//! });
|
||||
//!
|
||||
//! // Execute our server (modeled as a future) and wait for it to
|
||||
@@ -107,9 +105,6 @@ extern crate scoped_tls;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
mod slot;
|
||||
mod lock;
|
||||
|
||||
#[macro_use]
|
||||
pub mod io;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user