diff options
author | Carl Lerche <me@carllerche.com> | 2019-11-01 13:18:52 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-01 13:18:52 -0700 |
commit | d70c928d88dff9e3e8d673b8ee02bce131598550 (patch) | |
tree | 6b079db2f80bd61764203a32ffe48769d18c1386 /tokio/src/runtime/current_thread/mod.rs | |
parent | 742d89b0f333150f6a550ae7840235851f4eb069 (diff) |
runtime: merge multi & single threaded runtimes (#1716)
Simplify Tokio's runtime construct by combining both Runtime variants
into a single type. The execution style can be controlled by a
configuration setting on `Builder`.
The implication of this change is that there is no longer any way to
spawn `!Send` futures. This, however, is a temporary limitation. A
different strategy will be employed for supporting `!Send` futures.
Included in this patch is a rework of `task::JoinHandle` to support
using this type from both the thread-pool and current-thread executors.
Diffstat (limited to 'tokio/src/runtime/current_thread/mod.rs')
-rw-r--r-- | tokio/src/runtime/current_thread/mod.rs | 67 |
1 files changed, 0 insertions, 67 deletions
diff --git a/tokio/src/runtime/current_thread/mod.rs b/tokio/src/runtime/current_thread/mod.rs deleted file mode 100644 index 8a2d6028..00000000 --- a/tokio/src/runtime/current_thread/mod.rs +++ /dev/null @@ -1,67 +0,0 @@ -//! A runtime implementation that runs everything on the current thread. -//! -//! [`current_thread::Runtime`][rt] is similar to the primary -//! [`Runtime`][concurrent-rt] except that it runs all components on the current -//! thread instead of using a thread pool. This means that it is able to spawn -//! futures that do not implement `Send`. -//! -//! Same as the default [`Runtime`][concurrent-rt], the -//! [`current_thread::Runtime`][rt] includes: -//! -//! * A [reactor] to drive I/O resources. -//! * An [executor] to execute tasks that use these I/O resources. -//! * A [timer] for scheduling work to run after a set period of time. -//! -//! Note that [`current_thread::Runtime`][rt] does not implement `Send` itself -//! and cannot be safely moved to other threads. -//! -//! # Spawning from other threads -//! -//! While [`current_thread::Runtime`][rt] does not implement `Send` and cannot -//! safely be moved to other threads, it provides a `Handle` that can be sent -//! to other threads and allows to spawn new tasks from there. -//! -//! For example: -//! -//! ``` -//! use tokio::runtime::current_thread::Runtime; -//! use std::thread; -//! -//! let runtime = Runtime::new().unwrap(); -//! let handle = runtime.handle(); -//! -//! thread::spawn(move || { -//! let _ = handle.spawn(async { -//! println!("hello world"); -//! }); -//! }).join().unwrap(); -//! ``` -//! -//! # Examples -//! -//! Creating a new `Runtime` and running a future `f` until its completion and -//! returning its result. -//! -//! ``` -//! use tokio::runtime::current_thread::Runtime; -//! -//! let runtime = Runtime::new().unwrap(); -//! -//! // Use the runtime... -//! // runtime.block_on(f); // where f is a future -//! ``` -//! -//! [rt]: struct.Runtime.html -//! [concurrent-rt]: ../struct.Runtime.html -//! [chan]: https://docs.rs/futures/0.1/futures/sync/mpsc/fn.channel.html -//! [reactor]: ../../reactor/struct.Reactor.html -//! [executor]: https://tokio.rs/docs/internals/runtime-model/#executors -//! [timer]: ../../timer/index.html - -mod builder; -mod runtime; - -pub use self::builder::Builder; -pub use self::runtime::{Handle, Runtime, RunError}; -pub use crate::executor::current_thread::spawn; -pub use crate::executor::current_thread::TaskExecutor; |