From ac81046e24233504c05e2a2847876c431bd02f14 Mon Sep 17 00:00:00 2001 From: Taylor Cramer Date: Mon, 4 Nov 2019 16:07:23 -0800 Subject: [PATCH] Remove ThreadPool::run and mentions of default spawners Fixes #1757 Fixes #1758 --- futures-executor/src/local_pool.rs | 11 +---------- futures-executor/src/thread_pool.rs | 13 ------------- futures-util/src/task/spawn.rs | 4 ++-- futures/src/lib.rs | 30 +++++++---------------------- futures/tests/mutex.rs | 3 ++- 5 files changed, 12 insertions(+), 49 deletions(-) diff --git a/futures-executor/src/local_pool.rs b/futures-executor/src/local_pool.rs index 9985dca5b9..7046006b02 100644 --- a/futures-executor/src/local_pool.rs +++ b/futures-executor/src/local_pool.rs @@ -103,10 +103,6 @@ impl LocalPool { /// Run all tasks in the pool to completion. /// - /// The given spawner, `spawn`, is used as the default spawner for any - /// *newly*-spawned tasks. You can route these additional tasks back into - /// the `LocalPool` by using its spawner handle: - /// /// ``` /// use futures::executor::LocalPool; /// @@ -126,18 +122,13 @@ impl LocalPool { /// Runs all the tasks in the pool until the given future completes. /// - /// The given spawner, `spawn`, is used as the default spawner for any - /// *newly*-spawned tasks. You can route these additional tasks back into - /// the `LocalPool` by using its spawner handle: - /// /// ``` /// use futures::executor::LocalPool; /// /// let mut pool = LocalPool::new(); /// # let my_app = async {}; /// - /// // run tasks in the pool until `my_app` completes, by default spawning - /// // further tasks back onto the pool + /// // run tasks in the pool until `my_app` completes /// pool.run_until(my_app); /// ``` /// diff --git a/futures-executor/src/thread_pool.rs b/futures-executor/src/thread_pool.rs index fded082f27..893d9ae5fc 100644 --- a/futures-executor/src/thread_pool.rs +++ b/futures-executor/src/thread_pool.rs @@ -90,19 +90,6 @@ impl ThreadPool { ThreadPoolBuilder::new() } - /// Runs the given future with this thread pool as the default spawner for - /// spawning tasks. - /// - /// **This function will block the calling thread** until the given future - /// is complete. While executing that future, any tasks spawned onto the - /// default spawner will be routed to this thread pool. - /// - /// Note that the function will return when the provided future completes, - /// even if some of the tasks it spawned are still running. - pub fn run(&mut self, f: F) -> F::Output { - crate::LocalPool::new().run_until(f) - } - /// Spawns a future that will be run to completion. /// /// > **Note**: This method is similar to `Spawn::spawn_obj`, except that diff --git a/futures-util/src/task/spawn.rs b/futures-util/src/task/spawn.rs index e869f1ef55..a9a2e791b1 100644 --- a/futures-util/src/task/spawn.rs +++ b/futures-util/src/task/spawn.rs @@ -57,7 +57,7 @@ pub trait SpawnExt: Spawn { /// resolves to the output of the spawned future. /// /// ``` - /// use futures::executor::ThreadPool; + /// use futures::executor::{block_on, ThreadPool}; /// use futures::future; /// use futures::task::SpawnExt; /// @@ -65,7 +65,7 @@ pub trait SpawnExt: Spawn { /// /// let future = future::ready(1); /// let join_handle_fut = executor.spawn_with_handle(future).unwrap(); - /// assert_eq!(executor.run(join_handle_fut), 1); + /// assert_eq!(block_on(join_handle_fut), 1); /// ``` #[cfg(feature = "channel")] #[cfg(feature = "std")] diff --git a/futures/src/lib.rs b/futures/src/lib.rs index 4055a7f0c7..7fe16c8e33 100644 --- a/futures/src/lib.rs +++ b/futures/src/lib.rs @@ -131,25 +131,10 @@ pub mod executor { //! Most of the time tasks should be executed on a [thread //! pool](crate::executor::ThreadPool). A small set of worker threads can //! handle a very large set of spawned tasks (which are much lighter weight - //! than threads). - //! - //! The simplest way to use a thread pool is to - //! [`run`](crate::executor::ThreadPool::run) an initial task on it, which - //! can then spawn further tasks back onto the pool to complete its work: - //! - //! ``` - //! use futures::executor::ThreadPool; - //! # use futures::future::lazy; - //! # let my_app = lazy(|_| 42); - //! - //! // assuming `my_app: Future` - //! ThreadPool::new().expect("Failed to create threadpool").run(my_app); - //! ``` - //! - //! The call to [`run`](crate::executor::ThreadPool::run) will block the - //! current thread until the future defined by `my_app` completes, and will - //! return the result of that future. - //! + //! than threads). Tasks spawned onto the pool with the + //! [`spawn_ok()`](crate::executor::ThreadPool::spawn_ok) + //! function will run on ambiently on the created threads. + //! //! # Spawning additional tasks //! //! Tasks can be spawned onto a spawner by calling its @@ -169,10 +154,9 @@ pub mod executor { //! The `LocalPool` is best suited for running I/O-bound tasks that do //! relatively little work between I/O operations. //! - //! There is also a convenience function, - //! [`block_on`](crate::executor::block_on), for simply running a future to - //! completion on the current thread, while routing any spawned tasks - //! to a global thread pool. + //! There is also a convenience function + //! [`block_on`](crate::executor::block_on) for simply running a future to + //! completion on the current thread. pub use futures_executor::{ BlockingStream, diff --git a/futures/tests/mutex.rs b/futures/tests/mutex.rs index 3c6f02a9a7..2e49a87933 100644 --- a/futures/tests/mutex.rs +++ b/futures/tests/mutex.rs @@ -1,4 +1,5 @@ use futures::channel::mpsc; +use futures::executor::block_on; use futures::future::{ready, FutureExt}; use futures::lock::Mutex; use futures::stream::StreamExt; @@ -57,7 +58,7 @@ fn mutex_contested() { }).unwrap(); } - pool.run(async { + block_on(async { for _ in 0..num_tasks { let () = rx.next().await.unwrap(); }