pub struct TaskExecutor { /* private fields */ }
Expand description
Executes futures on the runtime
All futures spawned using this executor will be submitted to the associated Runtime’s executor. This executor is usually a thread pool.
For more details, see the module level documentation.
Implementations§
Source§impl TaskExecutor
impl TaskExecutor
Sourcepub fn spawn<F>(&self, future: F)
pub fn spawn<F>(&self, future: F)
Spawn a futures
0.1 future onto the Tokio runtime.
This spawns the given future onto the runtime’s executor, usually a thread pool. The thread pool is then responsible for polling the future until it completes.
See module level documentation for more details.
§Examples
use tokio_compat::runtime::Runtime;
// Create the runtime
let rt = Runtime::new().unwrap();
let executor = rt.executor();
// Spawn a `futures` 0.1 future onto the runtime
executor.spawn(futures_01::future::lazy(|| {
println!("now running on a worker thread");
Ok(())
}));
Sourcepub fn spawn_std<F>(&self, future: F)
pub fn spawn_std<F>(&self, future: F)
Spawn a std::future
future onto the Tokio runtime.
This spawns the given future onto the runtime’s executor, usually a thread pool. The thread pool is then responsible for polling the future until it completes.
See module level documentation for more details.
§Examples
use tokio_compat::runtime::Runtime;
// Create the runtime
let rt = Runtime::new().unwrap();
let executor = rt.executor();
// Spawn a `std::future` future onto the runtime
executor.spawn_std(async {
println!("now running on a worker thread");
});
Sourcepub fn spawn_handle<F>(
&self,
future: F,
) -> JoinHandle<Result<<F as Future>::Item, <F as Future>::Error>>
pub fn spawn_handle<F>( &self, future: F, ) -> JoinHandle<Result<<F as Future>::Item, <F as Future>::Error>>
Spawn a futures
0.1 future onto the Tokio runtime, returning a
JoinHandle
that can be used to await its result.
This spawns the given future onto the runtime’s executor, usually a thread pool. The thread pool is then responsible for polling the future until it completes.
Note that futures spawned in this manner do not “count” towards
keeping the runtime active for shutdown_on_idle
, since they are paired
with a JoinHandle
for awaiting their completion. See here for
details on shutting down the compatibility runtime.
§Examples
use tokio_compat::runtime::Runtime;
// Create the runtime
let rt = Runtime::new().unwrap();
let executor = rt.executor();
// Spawn a `futures` 0.1 future onto the runtime
executor.spawn(futures_01::future::lazy(|| {
println!("now running on a worker thread");
Ok(())
}));
Sourcepub fn spawn_handle_std<F>(
&self,
future: F,
) -> JoinHandle<<F as Future>::Output>
pub fn spawn_handle_std<F>( &self, future: F, ) -> JoinHandle<<F as Future>::Output>
Spawn a std::future
future onto the Tokio runtime, returning a
JoinHandle
that can be used to await its result.
This spawns the given future onto the runtime’s executor, usually a thread pool. The thread pool is then responsible for polling the future until it completes.
See module level documentation for more details.
Note that futures spawned in this manner do not “count” towards
keeping the runtime active for shutdown_on_idle
, since they are paired
with a JoinHandle
for awaiting their completion. See here for
details on shutting down the compatibility runtime.
§Examples
use tokio_compat::runtime::Runtime;
// Create the runtime
let rt = Runtime::new().unwrap();
let executor = rt.executor();
// Spawn a `std::future` future onto the runtime
executor.spawn_std(async {
println!("now running on a worker thread");
});
§Panics
This function panics if the spawn fails. Failure occurs if the executor is currently at capacity and is unable to spawn a new future.
Trait Implementations§
Source§impl Clone for TaskExecutor
impl Clone for TaskExecutor
Source§fn clone(&self) -> TaskExecutor
fn clone(&self) -> TaskExecutor
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more