Struct TaskExecutor

Source
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

Source

pub fn spawn<F>(&self, future: F)
where F: Future<Item = (), Error = ()> + Send + 'static,

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(())
}));
Source

pub fn spawn_std<F>(&self, future: F)
where F: Future<Output = ()> + Send + 'static,

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");
});
Source

pub fn spawn_handle<F>( &self, future: F, ) -> JoinHandle<Result<<F as Future>::Item, <F as Future>::Error>>
where F: Future + Send + 'static, <F as Future>::Item: Send + 'static, <F as Future>::Error: Send + 'static,

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(())
}));
Source

pub fn spawn_handle_std<F>( &self, future: F, ) -> JoinHandle<<F as Future>::Output>
where F: Future + Send + 'static, <F as Future>::Output: Send + 'static,

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

Source§

fn clone(&self) -> TaskExecutor

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TaskExecutor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T> Executor<T> for TaskExecutor
where T: Future<Item = (), Error = ()> + Send + 'static,

Source§

fn execute(&self, future: T) -> Result<(), ExecuteError<T>>

Spawns a future to run on this Executor, typically in the “background”. Read more
Source§

impl Executor for TaskExecutor

Source§

fn spawn( &mut self, future: Box<dyn Future<Item = (), Error = ()> + Send>, ) -> Result<(), SpawnError>

Spawns a future object to run on this executor. Read more
Source§

fn status(&self) -> Result<(), SpawnError>

Provides a best effort hint to whether or not spawn will succeed. Read more
Source§

impl<T> TypedExecutor<T> for TaskExecutor
where T: Future<Item = (), Error = ()> + Send + 'static,

Source§

fn spawn(&mut self, future: T) -> Result<(), SpawnError>

Spawns a future to run on this executor. Read more
Source§

fn status(&self) -> Result<(), SpawnError>

Provides a best effort hint to whether or not spawn will succeed. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Ex> Executor01CompatExt for Ex
where Ex: Executor<Compat<UnitError<FutureObj<'static, ()>>>> + Clone + Send + 'static,

Source§

fn compat(self) -> Executor01As03<Ex>

Converts a futures 0.1 Executor into a futures 0.3 Spawn. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.