Skip to content

Commit

Permalink
Remove ThreadPool::run and mentions of default spawners
Browse files Browse the repository at this point in the history
  • Loading branch information
cramertj committed Nov 5, 2019
1 parent 38b908f commit c851801
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 49 deletions.
11 changes: 1 addition & 10 deletions futures-executor/src/local_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
///
Expand All @@ -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);
/// ```
///
Expand Down
13 changes: 0 additions & 13 deletions futures-executor/src/thread_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<F: Future>(&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
Expand Down
4 changes: 2 additions & 2 deletions futures-util/src/task/spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ 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;
///
/// let mut executor = ThreadPool::new().unwrap();
///
/// 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")]
Expand Down
30 changes: 7 additions & 23 deletions futures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion futures/tests/mutex.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -57,7 +58,7 @@ fn mutex_contested() {
}).unwrap();
}

pool.run(async {
block_on(async {
for _ in 0..num_tasks {
let () = rx.next().await.unwrap();
}
Expand Down

0 comments on commit c851801

Please sign in to comment.