summaryrefslogtreecommitdiffstats
path: root/examples/hello_world.rs
diff options
context:
space:
mode:
authorCarl Lerche <me@carllerche.com>2018-02-21 07:42:22 -0800
committerGitHub <noreply@github.com>2018-02-21 07:42:22 -0800
commitfe14e7b127b17a1e8f267f467843d2a7355c94be (patch)
tree7f0dfa97c5b35a67d52b57d9ef10b0dbdd43208a /examples/hello_world.rs
parente0d95aa037c354240ea495542b7afe29ad30e337 (diff)
Introduce the Tokio runtime: Reactor + Threadpool (#141)
This patch is an intial implementation of the Tokio runtime. The Tokio runtime provides an out of the box configuration for running I/O heavy asynchronous applications. As of now, the Tokio runtime is a combination of a work-stealing thread pool as well as a background reactor to drive I/O resources. This patch also includes tokio-executor, a hopefully short lived crate that is based on the futures 0.2 executor RFC. * Implement `Park` for `Reactor` This enables the reactor to be used as the thread parker for executors. This also adds an `Error` component to `Park`. With this change, a `Reactor` and a `CurrentThread` can be combined to achieve the capabilities of tokio-core.
Diffstat (limited to 'examples/hello_world.rs')
-rw-r--r--examples/hello_world.rs32
1 files changed, 15 insertions, 17 deletions
diff --git a/examples/hello_world.rs b/examples/hello_world.rs
index 54a95128..1731f942 100644
--- a/examples/hello_world.rs
+++ b/examples/hello_world.rs
@@ -55,6 +55,8 @@ pub fn main() {
println!("accept error = {:?}", err);
});
+ println!("server running on localhost:6142");
+
// This starts the `current_thread` executor.
//
// Executors are responsible for scheduling many asynchronous tasks, driving
@@ -62,21 +64,17 @@ pub fn main() {
// implementations, each providing different scheduling characteristics.
//
// The `current_thread` executor multiplexes all scheduled tasks on the
- // current thread. This means that spawned tasks are not required to
- // implement `Send`.
- current_thread::run(|_| {
- // Now, the server task must be spawned.
- //
- // It's important to note that all futures / tasks are lazy. No work
- // will happen unless they are spawned onto an executor.
- current_thread::spawn(server);
-
- println!("server running on localhost:6142");
-
- // The `current_thread::run` function will now block until *all* spawned
- // tasks complete.
- //
- // In our example, we have not defined a shutdown strategy, so
- // this will block until `ctrl-c` is pressed at the terminal.
- });
+ // current thread. This means that spawned tasks must not implement `Send`.
+ // It's important to note that all futures / tasks are lazy. No work will
+ // happen unless they are spawned onto an executor.
+ //
+ // The executor will start running the `server` task, which, in turn, spawns
+ // new tasks for each incoming connection.
+ //
+ // The `current_thread::block_on_all` function will block until *all*
+ // spawned tasks complete.
+ //
+ // In our example, we have not defined a shutdown strategy, so this will
+ // block until `ctrl-c` is pressed at the terminal.
+ current_thread::block_on_all(server).unwrap();
}