[][src]Struct tokio_compat::runtime::current_thread::Handle

pub struct Handle { /* fields omitted */ }
This is supported on (feature="rt-current-thread" or feature="rt-full") and feature="rt-current-thread" only.

Handle to spawn a future on the corresponding CurrentThread runtime instance

Methods

impl Handle[src]

pub fn spawn<F>(&self, future: F) -> Result<(), SpawnError> where
    F: Future01<Item = (), Error = ()> + Send + 'static, 
[src]

This is supported on feature="rt-current-thread" or feature="rt-full" only.

Spawn a futures 0.1 future onto the CurrentThread runtime instance corresponding to this handle.

Note that unlike the tokio 0.1 version of this function, this method never actually returns Err — it returns Result only for API compatibility.

pub fn spawn_std<F>(&self, future: F) -> Result<(), SpawnError> where
    F: Future<Output = ()> + Send + 'static, 
[src]

This is supported on feature="rt-current-thread" or feature="rt-full" only.

Spawn a std::future future onto the CurrentThread runtime instance corresponding to this handle.

pub fn spawn_handle<F>(
    &self,
    future: F
) -> JoinHandle<Result<F::Item, F::Error>> where
    F: Future01 + Send + 'static,
    F::Item: Send + 'static,
    F::Error: Send + 'static, 
[src]

This is supported on feature="rt-current-thread" or feature="rt-full" only.

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.

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 `futures` 0.1 future onto the runtime
executor.spawn(futures_01::future::lazy(|| {
    println!("now running on a worker thread");
    Ok(())
}));

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

This is supported on feature="rt-current-thread" or feature="rt-full" only.

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

pub fn status(&self) -> Result<(), SpawnError>[src]

This is supported on feature="rt-current-thread" or feature="rt-full" only.

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

This function may return both false positives and false negatives. If status returns Ok, then a call to spawn will probably succeed, but may fail. If status returns Err, a call to spawn will probably fail, but may succeed.

This allows a caller to avoid creating the task if the call to spawn has a high likelihood of failing.

Trait Implementations

impl Clone for Handle[src]

impl Debug for Handle[src]

Auto Trait Implementations

impl !RefUnwindSafe for Handle

impl Send for Handle

impl Sync for Handle

impl Unpin for Handle

impl !UnwindSafe for Handle

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.